GCC Code Coverage Report


Directory: ./
File: sql/field.cc
Date: 2022-12-13 11:44:05
Exec Total Coverage
Lines: 4115 4699 87.6%
Branches: 3184 5205 61.2%

Line Branch Exec Source
1 /*
2 Copyright (c) 2000, 2022, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include "sql/field.h"
26
27 #include <float.h>
28 #include <stddef.h>
29
30 #include "m_ctype.h"
31 #include "my_config.h"
32 #ifdef HAVE_SYS_TIME_H
33 #include <sys/time.h>
34 #endif
35
36 #include <algorithm>
37 #include <cmath> // isnan
38 #include <memory> // unique_ptr
39 #include <optional>
40
41 #include "decimal.h"
42 #include "m_string.h"
43 #include "my_alloc.h"
44 #include "my_byteorder.h"
45 #include "my_compare.h"
46 #include "my_compiler.h"
47 #include "my_dbug.h"
48 #include "my_double2ulonglong.h"
49 #include "my_sqlcommand.h"
50 #include "myisampack.h"
51 #include "sql-common/json_binary.h" // json_binary::serialize
52 #include "sql-common/json_dom.h" // Json_dom, Json_wrapper
53 #include "sql/create_field.h"
54 #include "sql/current_thd.h"
55 #include "sql/dd/cache/dictionary_client.h"
56 #include "sql/dd/types/table.h"
57 #include "sql/dd_table_share.h" // dd_get_old_field_type
58 #include "sql/derror.h" // ER_THD
59 #include "sql/filesort.h" // change_double_for_sort
60 #include "sql/gis/rtree_support.h" // get_mbr_from_store
61 #include "sql/gis/srid.h"
62 #include "sql/handler.h"
63 #include "sql/item.h"
64 #include "sql/item_json_func.h" // ensure_utf8mb4
65 #include "sql/item_timefunc.h" // Item_func_now_local
66 #include "sql/join_optimizer/bit_utils.h"
67 #include "sql/json_diff.h" // Json_diff_vector
68 #include "sql/key.h"
69 #include "sql/log_event.h" // class Table_map_log_event
70 #include "sql/my_decimal.h"
71 #include "sql/mysqld.h" // log_10
72 #include "sql/protocol.h"
73 #include "sql/psi_memory_key.h"
74 #include "sql/rpl_replica.h" // rpl_master_has_bug
75 #include "sql/rpl_rli.h" // Relay_log_info
76 #include "sql/spatial.h" // Geometry
77 #include "sql/sql_base.h"
78 #include "sql/sql_class.h" // THD
79 #include "sql/sql_exception_handler.h" // handle_std_exception
80 #include "sql/sql_lex.h"
81 #include "sql/sql_time.h" // str_to_datetime_with_warn
82 #include "sql/sql_tmp_table.h" // create_tmp_field
83 #include "sql/srs_fetcher.h"
84 #include "sql/stateless_allocator.h"
85 #include "sql/strfunc.h" // find_type2
86 #include "sql/system_variables.h"
87 #include "sql/time_zone_common.h"
88 #include "sql/transaction_info.h"
89 #include "sql/tztime.h" // Time_zone
90 #include "template_utils.h" // pointer_cast
91 #include "typelib.h"
92
93 namespace dd {
94 class Spatial_reference_system;
95 } // namespace dd
96
97 using std::max;
98 using std::min;
99
100 #define FLAGSTR(V, F) ((V) & (F) ? #F " " : "")
101
102 // Maximum allowed exponent value for converting string to decimal
103 #define MAX_EXPONENT 1024
104
105 /**
106 Static variables
107 */
108 const char field_separator = ',';
109 uchar Field::dummy_null_buffer = ' ';
110
111 #define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER
112 #define LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128
113 #define DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128
114 #define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
115 ((ulong)((1LL << std::min(arg, 4U) * 8) - 1LL))
116
117 /*
118 Rules for merging different types of fields in UNION
119
120 NOTE: to avoid 256*256 table, gap in table types numeration is skipped
121 following #defines describe that gap and how to canculate number of fields
122 and index of field in this array.
123 */
124 #define FIELDTYPE_TEAR_FROM (MYSQL_TYPE_BIT + 1)
125 #define FIELDTYPE_TEAR_TO (243 - 1)
126 #define FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO))
127
128 namespace {
129 /**
130 Predicate to determine if a field type change prevents alter
131 from being done inplace.
132
133 @param from - existing Field object.
134 @param to - Create_field object describing new version of field.
135
136 @return true if alter cannot be done inplace due to specified
137 condition, false otherwise.
138 */
139 386240 bool sql_type_prevents_inplace(const Field &from, const Create_field &to) {
140
1/2
✓ Branch 0 taken 386240 times.
✗ Branch 1 not taken.
386240 DBUG_TRACE;
141
1/2
✓ Branch 0 taken 386240 times.
✗ Branch 1 not taken.
772480 return to.sql_type != from.real_type();
142 386240 }
143
144 /**
145 Predicate to determine if a length change prevents alter from being
146 done inplace. Length cannot decrease and cannot cross the 256 byte
147 row format barrier.
148
149 @param from - existing Field object.
150 @param to - Create_field object describing new version of field.
151
152 @return true if alter cannot be done inplace due to specified
153 condition, false otherwise.
154 */
155 135058 bool length_prevents_inplace(const Field &from, const Create_field &to) {
156
1/2
✓ Branch 0 taken 135058 times.
✗ Branch 1 not taken.
135058 DBUG_TRACE;
157
8/14
✓ Branch 0 taken 135058 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135058 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 135057 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
135058 DBUG_PRINT(
158 "inplace",
159 ("from:%p, to.field:%p, to.field->row_pack_length():%u, "
160 "to.max_display_width_in_bytes():%zu",
161 &from, to.field, to.field ? to.field->row_pack_length() : (uint)-1,
162 to.max_display_width_in_bytes()));
163
164
4/6
✓ Branch 0 taken 135058 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135058 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1090 times.
✓ Branch 5 taken 133968 times.
135058 if (to.pack_length() < from.pack_length()) {
165
3/16
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1090 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1090 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
1090 DBUG_PRINT(
166 "inplace",
167 ("decreasing pack_length from %u to %zu, -> true for '%s'",
168 from.pack_length(), to.pack_length(), current_thd->query().str));
169 1090 return true;
170 }
171
172
8/10
✓ Branch 0 taken 133968 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29329 times.
✓ Branch 3 taken 104639 times.
✓ Branch 4 taken 29329 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 501 times.
✓ Branch 7 taken 28828 times.
✓ Branch 8 taken 501 times.
✓ Branch 9 taken 133467 times.
133968 if (to.max_display_width_in_bytes() >= 256 && from.row_pack_length() < 256) {
173
3/16
✓ Branch 0 taken 501 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 501 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 501 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
501 DBUG_PRINT("inplace",
174 ("row_pack_length increases past the 256 threshold, from %u to "
175 "%zu, -> true for '%s'",
176 from.row_pack_length(), to.max_display_width_in_bytes(),
177 current_thd->query().str));
178
3/12
✓ Branch 0 taken 501 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 501 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 501 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
501 DBUG_PRINT("inplace",
179 ("from:%p, to.field:%p, to.field->row_pack_length():%u", &from,
180 to.field, to.field ? to.field->row_pack_length() : (uint)-1));
181 501 return true;
182 }
183
5/8
✓ Branch 0 taken 133467 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 133467 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 133466 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
133467 DBUG_PRINT("inplace", ("-> false"));
184 133467 return false;
185 135058 }
186
187 /**
188 Predicate to determine if a charset change prevents alter from being
189 done inplace.
190
191 For changes other than the following, we can immediately reject using
192 the inplace algorithm:
193
194 - Changing collation while keeping the charset.
195 - Changing any charset to the binary charset.
196 - Changing utf8mb3 to utf8mb4.
197
198 @note The changes listed above are potentially acceptable if the field
199 is not indexed in the target table. This information is not available
200 here, and is checked later in fill_alter_inplace_info().
201
202 @note ASCII cannot be converted to UTF-8 inplace because inserting
203 non-ascii values into an ASCII column only trigger a warning not an
204 error.
205
206 @param from - existing Field object.
207 @param to - Create_field object describing new version of field.
208
209 @return true if alter cannot be done inplace due to specified
210 condition, false otherwise.
211 */
212 231501 bool charset_prevents_inplace(const Field_str &from, const Create_field &to) {
213
1/2
✓ Branch 0 taken 231501 times.
✗ Branch 1 not taken.
231501 DBUG_TRACE;
214
215
6/8
✓ Branch 0 taken 231501 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 231501 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1934 times.
✓ Branch 5 taken 229567 times.
✓ Branch 6 taken 229612 times.
✓ Branch 7 taken 1889 times.
233435 if (my_charset_same(to.charset, from.charset()) ||
216
3/4
✓ Branch 0 taken 1934 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✓ Branch 3 taken 1889 times.
1934 my_charset_same(to.charset, &my_charset_bin)) {
217 229612 return false;
218 }
219
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 1725 times.
2053 return (0 != strcmp(to.charset->csname, MY_UTF8MB4) ||
220
3/4
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 73 times.
✓ Branch 3 taken 91 times.
2053 0 != strcmp(from.charset()->csname, "utf8mb3"));
221 231501 }
222
223 /**
224 Predicate to determine if the difference between a Field and the
225 new Create_field prevents alter from being done
226 inplace. Convenience wrapper for the preceding predicates.
227
228 @param from - existing Field object.
229 @param to - Create_field object describing new version of field.
230
231 @return true if alter cannot be done inplace due to specified
232 condition, false otherwise.
233 */
234 136789 bool change_prevents_inplace(const Field_str &from, const Create_field &to) {
235
1/2
✓ Branch 0 taken 136789 times.
✗ Branch 1 not taken.
136789 DBUG_TRACE;
236
1/2
✓ Branch 0 taken 136789 times.
✗ Branch 1 not taken.
136789 return sql_type_prevents_inplace(from, to) ||
237
5/6
✓ Branch 0 taken 135058 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 133467 times.
✓ Branch 3 taken 1591 times.
✓ Branch 4 taken 133461 times.
✓ Branch 5 taken 6 times.
268525 length_prevents_inplace(from, to) ||
238 // Changing column format to/from compressed or changing associated
239 // compression dictionary must result in table rebuild
240
2/2
✓ Branch 0 taken 135058 times.
✓ Branch 1 taken 1731 times.
405314 from.has_different_compression_attributes_with(to) ||
241
3/4
✓ Branch 0 taken 133461 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1790 times.
✓ Branch 3 taken 131671 times.
270250 charset_prevents_inplace(from, to);
242 136789 }
243 } // namespace
244
245 20691689 inline int field_type2index(enum_field_types field_type) {
246 20691689 field_type = real_type_to_type(field_type);
247
3/4
✓ Branch 0 taken 2824879 times.
✓ Branch 1 taken 17866810 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2824879 times.
20691689 assert(field_type < FIELDTYPE_TEAR_FROM || field_type > FIELDTYPE_TEAR_TO);
248 20691689 return (field_type < FIELDTYPE_TEAR_FROM
249
2/2
✓ Branch 0 taken 2824879 times.
✓ Branch 1 taken 17866810 times.
20691689 ? field_type
250 2824879 : ((int)FIELDTYPE_TEAR_FROM) + (field_type - FIELDTYPE_TEAR_TO) -
251 20691689 1);
252 }
253
254 static enum_field_types field_types_merge_rules[FIELDTYPE_NUM][FIELDTYPE_NUM] =
255 {
256 /* MYSQL_TYPE_DECIMAL -> */
257 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
258 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
259 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
260 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
261 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
262 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
263 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
264 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
265 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
266 MYSQL_TYPE_DECIMAL, MYSQL_TYPE_DECIMAL,
267 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
268 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
269 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
270 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
271 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
272 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
273 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
274 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_INVALID,
275 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
276 MYSQL_TYPE_DECIMAL, MYSQL_TYPE_VARCHAR,
277 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
278 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
279 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
280 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
281 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
282 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
283 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
284 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
285 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
286 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
287 /* MYSQL_TYPE_TINY -> */
288 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
289 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY,
290 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
291 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
292 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
293 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
294 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
295 MYSQL_TYPE_TINY, MYSQL_TYPE_VARCHAR,
296 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
297 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24,
298 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
299 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
300 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
301 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY,
302 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
303 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
304 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
305 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID,
306 // MYSQL_TYPE_BOOL MYSQL_TYPE_TINY
307 MYSQL_TYPE_TINY, MYSQL_TYPE_VARCHAR,
308 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
309 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
310 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
311 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
312 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
313 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
314 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
315 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
316 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
317 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
318 /* MYSQL_TYPE_SHORT -> */
319 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
320 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_SHORT,
321 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
322 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
323 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
324 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
325 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
326 MYSQL_TYPE_SHORT, MYSQL_TYPE_VARCHAR,
327 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
328 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24,
329 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
330 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
331 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
332 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_SHORT,
333 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
334 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
335 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
336 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID,
337 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
338 MYSQL_TYPE_SHORT, MYSQL_TYPE_VARCHAR,
339 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
340 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
341 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
342 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
343 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
344 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
345 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
346 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
347 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
348 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
349 /* MYSQL_TYPE_LONG -> */
350 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
351 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONG,
352 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
353 MYSQL_TYPE_LONG, MYSQL_TYPE_LONG,
354 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
355 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
356 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
357 MYSQL_TYPE_LONG, MYSQL_TYPE_VARCHAR,
358 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
359 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONG,
360 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
361 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
362 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
363 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONG,
364 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
365 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
366 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
367 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID,
368 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
369 MYSQL_TYPE_LONG, MYSQL_TYPE_VARCHAR,
370 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
371 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
372 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
373 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
374 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
375 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
376 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
377 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
378 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
379 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
380 /* MYSQL_TYPE_FLOAT -> */
381 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
382 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_FLOAT,
383 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
384 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
385 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
386 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
387 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
388 MYSQL_TYPE_FLOAT, MYSQL_TYPE_VARCHAR,
389 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
390 MYSQL_TYPE_FLOAT, MYSQL_TYPE_FLOAT,
391 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
392 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
393 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
394 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_FLOAT,
395 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
396 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
397 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
398 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_INVALID,
399 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
400 MYSQL_TYPE_FLOAT, MYSQL_TYPE_VARCHAR,
401 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
402 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR,
403 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
404 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
405 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
406 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
407 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
408 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
409 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
410 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
411 /* MYSQL_TYPE_DOUBLE -> */
412 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
413 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
414 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
415 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
416 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
417 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
418 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
419 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR,
420 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
421 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
422 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
423 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
424 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
425 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_DOUBLE,
426 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
427 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
428 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
429 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_INVALID,
430 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
431 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR,
432 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
433 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_VARCHAR,
434 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
435 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
436 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
437 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
438 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
439 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
440 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
441 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
442 /* MYSQL_TYPE_NULL -> */
443 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
444 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY,
445 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
446 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
447 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
448 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
449 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
450 MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
451 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
452 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG,
453 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
454 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_TIME,
455 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
456 MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
457 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
458 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
459 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
460 MYSQL_TYPE_BIT, MYSQL_TYPE_INVALID,
461 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
462 MYSQL_TYPE_BOOL, MYSQL_TYPE_JSON,
463 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
464 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_ENUM,
465 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
466 MYSQL_TYPE_SET, MYSQL_TYPE_TINY_BLOB,
467 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
468 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
469 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
470 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
471 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
472 MYSQL_TYPE_STRING, MYSQL_TYPE_GEOMETRY},
473 /* MYSQL_TYPE_TIMESTAMP -> */
474 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
475 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
476 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
477 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
478 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
479 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
480 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
481 MYSQL_TYPE_TIMESTAMP, MYSQL_TYPE_TIMESTAMP,
482 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
483 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
484 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
485 MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
486 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
487 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
488 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
489 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
490 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
491 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID,
492 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
493 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
494 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
495 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
496 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
497 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
498 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
499 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
500 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
501 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
502 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
503 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
504 /* MYSQL_TYPE_LONGLONG -> */
505 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
506 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONGLONG,
507 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
508 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG,
509 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
510 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
511 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
512 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_VARCHAR,
513 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
514 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG,
515 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
516 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
517 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
518 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONGLONG,
519 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
520 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
521 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
522 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID,
523 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
524 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_VARCHAR,
525 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
526 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
527 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
528 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
529 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
530 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
531 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
532 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
533 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
534 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
535 /* MYSQL_TYPE_INT24 -> */
536 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
537 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_INT24,
538 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
539 MYSQL_TYPE_INT24, MYSQL_TYPE_LONG,
540 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
541 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
542 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
543 MYSQL_TYPE_INT24, MYSQL_TYPE_VARCHAR,
544 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
545 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24,
546 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
547 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
548 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
549 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INT24,
550 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
551 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
552 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
553 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID,
554 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
555 MYSQL_TYPE_INT24, MYSQL_TYPE_VARCHAR,
556 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
557 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
558 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
559 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
560 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
561 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
562 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
563 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
564 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
565 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
566 /* MYSQL_TYPE_DATE -> */
567 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
568 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
569 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
570 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
571 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
572 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
573 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
574 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
575 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
576 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
577 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
578 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
579 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
580 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
581 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
582 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
583 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
584 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID,
585 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
586 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
587 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
588 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
589 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
590 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
591 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
592 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
593 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
594 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
595 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
596 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
597 /* MYSQL_TYPE_TIME -> */
598 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
599 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
600 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
601 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
602 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
603 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
604 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
605 MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME,
606 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
607 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
608 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
609 MYSQL_TYPE_DATETIME, MYSQL_TYPE_TIME,
610 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
611 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
612 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
613 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
614 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
615 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID,
616 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
617 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
618 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
619 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
620 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
621 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
622 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
623 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
624 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
625 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
626 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
627 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
628 /* MYSQL_TYPE_DATETIME -> */
629 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
630 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
631 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
632 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
633 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
634 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
635 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
636 MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
637 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
638 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
639 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
640 MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
641 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
642 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
643 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
644 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
645 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
646 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID,
647 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
648 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
649 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
650 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
651 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
652 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
653 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
654 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
655 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
656 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
657 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
658 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
659 /* MYSQL_TYPE_YEAR -> */
660 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
661 MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
662 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
663 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
664 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
665 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
666 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
667 MYSQL_TYPE_YEAR, MYSQL_TYPE_VARCHAR,
668 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
669 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24,
670 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
671 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
672 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
673 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_YEAR,
674 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
675 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
676 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
677 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID,
678 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
679 MYSQL_TYPE_SHORT, MYSQL_TYPE_VARCHAR,
680 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
681 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
682 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
683 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
684 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
685 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
686 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
687 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
688 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
689 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
690 /* MYSQL_TYPE_NEWDATE -> */
691 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
692 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
693 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
694 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
695 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
696 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
697 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
698 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
699 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
700 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
701 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
702 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_DATETIME,
703 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
704 MYSQL_TYPE_DATETIME, MYSQL_TYPE_VARCHAR,
705 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
706 MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
707 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
708 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID,
709 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
710 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
711 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
712 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
713 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
714 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
715 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
716 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
717 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
718 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
719 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
720 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
721 /* MYSQL_TYPE_VARCHAR -> */
722 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
723 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
724 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
725 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
726 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
727 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
728 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
729 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
730 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
731 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
732 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
733 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
734 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
735 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
736 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
737 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
738 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
739 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID,
740 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
741 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
742 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
743 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
744 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
745 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
746 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
747 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
748 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
749 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
750 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
751 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR},
752 /* MYSQL_TYPE_BIT -> */
753 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
754 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_LONGLONG,
755 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
756 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG,
757 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
758 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
759 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
760 MYSQL_TYPE_BIT, MYSQL_TYPE_VARCHAR,
761 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
762 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG,
763 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
764 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
765 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
766 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONGLONG,
767 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
768 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
769 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
770 MYSQL_TYPE_BIT, MYSQL_TYPE_INVALID,
771 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
772 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_VARCHAR,
773 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
774 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
775 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
776 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
777 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
778 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
779 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
780 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
781 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
782 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
783 /* MYSQL_TYPE_INVALID -> */
784 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
785 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
786 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
787 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
788 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
789 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
790 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
791 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
792 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
793 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
794 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
795 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
796 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
797 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
798 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
799 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
800 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
801 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
802 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
803 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
804 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
805 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
806 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
807 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
808 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
809 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
810 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
811 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID,
812 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
813 MYSQL_TYPE_INVALID, MYSQL_TYPE_INVALID},
814 /* MYSQL_TYPE_BOOL -> */
815 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
816 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_TINY,
817 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
818 MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
819 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
820 MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
821 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
822 MYSQL_TYPE_BOOL, MYSQL_TYPE_VARCHAR,
823 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
824 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24,
825 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
826 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
827 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
828 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_SHORT,
829 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
830 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
831 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
832 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INVALID,
833 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
834 MYSQL_TYPE_BOOL, MYSQL_TYPE_VARCHAR,
835 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
836 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
837 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
838 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
839 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
840 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
841 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
842 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
843 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
844 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
845 /* MYSQL_TYPE_JSON -> */
846 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
847 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
848 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
849 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
850 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
851 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
852 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
853 MYSQL_TYPE_JSON, MYSQL_TYPE_VARCHAR,
854 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
855 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
856 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
857 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
858 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
859 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
860 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
861 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
862 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
863 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID,
864 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
865 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_JSON,
866 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
867 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
868 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
869 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_LONG_BLOB,
870 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
871 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
872 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
873 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_VARCHAR,
874 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
875 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
876 /* MYSQL_TYPE_NEWDECIMAL -> */
877 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
878 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
879 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
880 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
881 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
882 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
883 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
884 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
885 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
886 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
887 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
888 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
889 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
890 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_NEWDECIMAL,
891 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
892 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
893 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
894 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_INVALID,
895 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
896 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
897 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
898 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
899 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
900 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
901 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
902 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
903 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
904 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
905 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
906 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
907 /* MYSQL_TYPE_ENUM -> */
908 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
909 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
910 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
911 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
912 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
913 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
914 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
915 MYSQL_TYPE_ENUM, MYSQL_TYPE_VARCHAR,
916 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
917 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
918 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
919 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
920 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
921 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
922 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
923 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
924 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
925 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID,
926 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
927 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
928 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
929 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
930 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
931 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
932 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
933 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
934 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
935 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
936 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
937 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
938 /* MYSQL_TYPE_SET -> */
939 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
940 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
941 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
942 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
943 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
944 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
945 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
946 MYSQL_TYPE_SET, MYSQL_TYPE_VARCHAR,
947 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
948 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
949 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
950 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
951 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
952 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
953 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
954 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
955 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
956 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID,
957 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
958 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
959 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
960 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
961 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
962 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
963 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
964 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
965 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
966 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
967 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
968 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR},
969 /* MYSQL_TYPE_TINY_BLOB -> */
970 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
971 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
972 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
973 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
974 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
975 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
976 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
977 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
978 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
979 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
980 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
981 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
982 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
983 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
984 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
985 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
986 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
987 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_INVALID,
988 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
989 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_LONG_BLOB,
990 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
991 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
992 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
993 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB,
994 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
995 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
996 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
997 MYSQL_TYPE_BLOB, MYSQL_TYPE_TINY_BLOB,
998 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
999 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_TINY_BLOB},
1000 /* MYSQL_TYPE_MEDIUM_BLOB -> */
1001 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
1002 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
1003 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
1004 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
1005 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
1006 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
1007 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
1008 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
1009 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
1010 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
1011 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
1012 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
1013 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
1014 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
1015 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
1016 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
1017 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
1018 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_INVALID,
1019 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
1020 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
1021 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
1022 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
1023 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
1024 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
1025 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
1026 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
1027 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
1028 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
1029 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
1030 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_MEDIUM_BLOB},
1031 /* MYSQL_TYPE_LONG_BLOB -> */
1032 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
1033 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1034 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
1035 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1036 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
1037 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1038 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
1039 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1040 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
1041 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1042 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
1043 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1044 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
1045 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1046 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
1047 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1048 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
1049 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_INVALID,
1050 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
1051 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1052 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
1053 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1054 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
1055 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1056 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
1057 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1058 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
1059 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB,
1060 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
1061 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONG_BLOB},
1062 /* MYSQL_TYPE_BLOB -> */
1063 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
1064 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1065 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
1066 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1067 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
1068 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1069 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
1070 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1071 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
1072 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1073 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
1074 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1075 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
1076 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1077 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
1078 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1079 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
1080 MYSQL_TYPE_BLOB, MYSQL_TYPE_INVALID,
1081 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
1082 MYSQL_TYPE_BLOB, MYSQL_TYPE_LONG_BLOB,
1083 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
1084 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1085 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
1086 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1087 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
1088 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
1089 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
1090 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1091 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
1092 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB},
1093 /* MYSQL_TYPE_VAR_STRING -> */
1094 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
1095 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1096 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
1097 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1098 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
1099 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1100 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
1101 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1102 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
1103 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1104 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
1105 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1106 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
1107 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1108 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
1109 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1110 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
1111 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID,
1112 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
1113 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1114 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
1115 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1116 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
1117 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
1118 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
1119 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
1120 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
1121 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
1122 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
1123 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR},
1124 /* MYSQL_TYPE_STRING -> */
1125 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
1126 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
1127 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
1128 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
1129 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
1130 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
1131 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
1132 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
1133 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
1134 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
1135 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
1136 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
1137 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
1138 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
1139 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
1140 MYSQL_TYPE_STRING, MYSQL_TYPE_VARCHAR,
1141 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
1142 MYSQL_TYPE_STRING, MYSQL_TYPE_INVALID,
1143 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
1144 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
1145 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
1146 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
1147 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
1148 MYSQL_TYPE_STRING, MYSQL_TYPE_TINY_BLOB,
1149 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
1150 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
1151 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
1152 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
1153 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
1154 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING},
1155 /* MYSQL_TYPE_GEOMETRY -> */
1156 {// MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
1157 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1158 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
1159 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1160 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
1161 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1162 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
1163 MYSQL_TYPE_GEOMETRY, MYSQL_TYPE_VARCHAR,
1164 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
1165 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1166 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
1167 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1168 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
1169 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1170 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
1171 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1172 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
1173 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_INVALID,
1174 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
1175 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1176 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
1177 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
1178 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
1179 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_TINY_BLOB,
1180 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
1181 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB,
1182 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
1183 MYSQL_TYPE_BLOB, MYSQL_TYPE_VARCHAR,
1184 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
1185 MYSQL_TYPE_STRING, MYSQL_TYPE_GEOMETRY}};
1186
1187 7061 bool pre_validate_value_generator_expr(Item *expression, const char *name,
1188 Value_generator_source source) {
1189 enum error_type { ER_GENERATED_ROW, ER_NAMED_FUNCTION, MAX_ERROR };
1190 7061 int error_code_map[][MAX_ERROR] = {
1191 // Generated column
1192 {ER_GENERATED_COLUMN_ROW_VALUE,
1193 ER_GENERATED_COLUMN_NAMED_FUNCTION_IS_NOT_ALLOWED},
1194 // Default expression
1195 {ER_DEFAULT_VAL_GENERATED_ROW_VALUE,
1196 ER_DEFAULT_VAL_GENERATED_NAMED_FUNCTION_IS_NOT_ALLOWED},
1197 // Check constraint
1198 {ER_CHECK_CONSTRAINT_ROW_VALUE,
1199 ER_CHECK_CONSTRAINT_NAMED_FUNCTION_IS_NOT_ALLOWED}};
1200
1201 // ROW values are not allowed
1202
3/4
✓ Branch 0 taken 7061 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 7059 times.
7061 if (expression->type() == Item::ROW_ITEM) {
1203
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 my_error(error_code_map[source][ER_GENERATED_ROW], MYF(0), name);
1204 2 return true;
1205 }
1206
1207 Check_function_as_value_generator_parameters checker_args(
1208 7059 error_code_map[source][ER_NAMED_FUNCTION], source);
1209
1210
3/4
✓ Branch 0 taken 7059 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
✓ Branch 3 taken 6966 times.
7059 if (expression->walk(&Item::check_function_as_value_generator,
1211 enum_walk::SUBQUERY_POSTFIX,
1212 pointer_cast<uchar *>(&checker_args))) {
1213
1/2
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
93 my_error(checker_args.err_code, MYF(0), name,
1214 checker_args.banned_function_name);
1215 93 return true;
1216 }
1217
1218 6966 return false;
1219 }
1220
1221 /**
1222 Set field to temporary value NULL.
1223 */
1224 1625 void Field::set_tmp_null() {
1225 1625 m_is_tmp_null = true;
1226
1227 1625 m_check_for_truncated_fields_saved = current_thd->check_for_truncated_fields;
1228 1625 }
1229
1230 uint Field::is_equal(const Create_field *new_field) const {
1231 return (real_type() == new_field->sql_type);
1232 }
1233 /**
1234 Return type of which can carry value of both given types in UNION result.
1235
1236 @param a type for merging
1237 @param b type for merging
1238
1239 @return
1240 type of field
1241 */
1242
1243 6168618 enum_field_types Field::field_type_merge(enum_field_types a,
1244 enum_field_types b) {
1245
2/4
✓ Branch 0 taken 6168618 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6168618 times.
✗ Branch 3 not taken.
6168618 assert(a != MYSQL_TYPE_INVALID && b != MYSQL_TYPE_INVALID);
1246 6168618 return field_types_merge_rules[field_type2index(a)][field_type2index(b)];
1247 }
1248
1249 static Item_result field_types_result_type[FIELDTYPE_NUM] = {
1250 // MYSQL_TYPE_DECIMAL MYSQL_TYPE_TINY
1251 DECIMAL_RESULT, INT_RESULT,
1252 // MYSQL_TYPE_SHORT MYSQL_TYPE_LONG
1253 INT_RESULT, INT_RESULT,
1254 // MYSQL_TYPE_FLOAT MYSQL_TYPE_DOUBLE
1255 REAL_RESULT, REAL_RESULT,
1256 // MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
1257 STRING_RESULT, STRING_RESULT,
1258 // MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
1259 INT_RESULT, INT_RESULT,
1260 // MYSQL_TYPE_DATE MYSQL_TYPE_TIME
1261 STRING_RESULT, STRING_RESULT,
1262 // MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
1263 STRING_RESULT, INT_RESULT,
1264 // MYSQL_TYPE_NEWDATE MYSQL_TYPE_VARCHAR
1265 STRING_RESULT, STRING_RESULT,
1266 // MYSQL_TYPE_BIT MYSQL_TYPE_INVALID
1267 INT_RESULT, INVALID_RESULT,
1268 // Unused entries: <17>-<242>
1269 // MYSQL_TYPE_BOOL MYSQL_TYPE_JSON
1270 INT_RESULT, STRING_RESULT,
1271 // MYSQL_TYPE_NEWDECIMAL MYSQL_TYPE_ENUM
1272 DECIMAL_RESULT, STRING_RESULT,
1273 // MYSQL_TYPE_SET MYSQL_TYPE_TINY_BLOB
1274 STRING_RESULT, STRING_RESULT,
1275 // MYSQL_TYPE_MEDIUM_BLOB MYSQL_TYPE_LONG_BLOB
1276 STRING_RESULT, STRING_RESULT,
1277 // MYSQL_TYPE_BLOB MYSQL_TYPE_VAR_STRING
1278 STRING_RESULT, STRING_RESULT,
1279 // MYSQL_TYPE_STRING MYSQL_TYPE_GEOMETRY
1280 STRING_RESULT, STRING_RESULT};
1281
1282 /**
1283 Convert Field::geometry_type to the corresponding Geometry::wkbType.
1284
1285 @param t The geometry_type to convert
1286
1287 @return The corresponding Geometry::wkbType, or
1288 Geometry::wkb_invalid_type if there's not suitable type.
1289 */
1290 2681451 static Geometry::wkbType geometry_type_to_wkb_type(Field::geometry_type t) {
1291
9/9
✓ Branch 0 taken 948036 times.
✓ Branch 1 taken 1731683 times.
✓ Branch 2 taken 387 times.
✓ Branch 3 taken 441 times.
✓ Branch 4 taken 192 times.
✓ Branch 5 taken 230 times.
✓ Branch 6 taken 258 times.
✓ Branch 7 taken 223 times.
✓ Branch 8 taken 1 times.
2681451 switch (t) {
1292 948036 case Field::GEOM_GEOMETRY:
1293 948036 return Geometry::wkb_invalid_type;
1294 1731683 case Field::GEOM_POINT:
1295 1731683 return Geometry::wkb_point;
1296 387 case Field::GEOM_LINESTRING:
1297 387 return Geometry::wkb_linestring;
1298 441 case Field::GEOM_POLYGON:
1299 441 return Geometry::wkb_polygon;
1300 192 case Field::GEOM_MULTIPOINT:
1301 192 return Geometry::wkb_multipoint;
1302 230 case Field::GEOM_MULTILINESTRING:
1303 230 return Geometry::wkb_multilinestring;
1304 258 case Field::GEOM_MULTIPOLYGON:
1305 258 return Geometry::wkb_multipolygon;
1306 223 case Field::GEOM_GEOMETRYCOLLECTION:
1307 223 return Geometry::wkb_geometrycollection;
1308 1 default:
1309 1 assert(0);
1310 return Geometry::wkb_invalid_type;
1311 }
1312 }
1313
1314 /*
1315 Test if the given string contains important data:
1316 not spaces for character string,
1317 or any data for binary string.
1318
1319 SYNOPSIS
1320 test_if_important_data()
1321 cs Character set
1322 str String to test
1323 strend String end
1324
1325 RETURN
1326 false - If string does not have important data
1327 true - If string has some important data
1328 */
1329
1330 1219684 static bool test_if_important_data(const CHARSET_INFO *cs, const char *str,
1331 const char *strend) {
1332
2/2
✓ Branch 0 taken 1215021 times.
✓ Branch 1 taken 4663 times.
1219684 if (cs != &my_charset_bin)
1333 1215021 str += cs->cset->scan(cs, str, strend, MY_SEQ_SPACES);
1334 1219684 return (str < strend);
1335 }
1336
1337 /**
1338 Function to compare two unsigned integers for their relative order.
1339 Used below. In an anonymous namespace to not clash with definitions
1340 in other files.
1341 */
1342
1343 namespace {
1344
1345 203075 int compare(unsigned int a, unsigned int b) {
1346
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 202971 times.
203075 if (a < b) return -1;
1347
2/2
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 202882 times.
202971 if (b < a) return 1;
1348 202882 return 0;
1349 }
1350
1351 } // namespace
1352
1353 /**
1354 Detect Item_result by given field type of UNION merge result.
1355
1356 @param field_type given field type
1357
1358 @return
1359 Item_result (type of internal MySQL expression result)
1360 */
1361
1362 8345952 Item_result Field::result_merge_type(enum_field_types field_type) {
1363 8345952 return field_types_result_type[field_type2index(field_type)];
1364 }
1365
1366 /*****************************************************************************
1367 Static help functions
1368 *****************************************************************************/
1369
1370 /**
1371 Output a warning for erroneous conversion of strings to numerical
1372 values. For use with ER_TRUNCATED_WRONG_VALUE[_FOR_FIELD]
1373
1374 @param thd THD object
1375 @param str pointer to string that failed to be converted
1376 @param length length of string
1377 @param cs charset for string
1378 @param typestr string describing type converted to
1379 @param error error value to output
1380 @param field_name (for *_FOR_FIELD) name of field
1381 @param row_num (for *_FOR_FIELD) row number
1382 */
1383 1123 static void push_numerical_conversion_warning(
1384 THD *thd, const char *str, uint length, const CHARSET_INFO *cs,
1385 const char *typestr, int error, const char *field_name = "UNKNOWN",
1386 ulong row_num = 0) {
1387 char buf[std::max(std::max(DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE,
1388 LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE),
1389 DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE)];
1390
1391 1123 String tmp(buf, sizeof(buf), cs);
1392
1/2
✓ Branch 0 taken 1123 times.
✗ Branch 1 not taken.
1123 tmp.copy(str, length, cs);
1393
3/6
✓ Branch 0 taken 1123 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1123 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1123 times.
✗ Branch 5 not taken.
1123 push_warning_printf(thd, Sql_condition::SL_WARNING, error,
1394 ER_THD_NONCONST(thd, error), typestr, tmp.c_ptr(),
1395 field_name, row_num);
1396 1123 }
1397
1398 /**
1399 Emits a warning for the decimal conversion error. May modify
1400 dec_value if there was conversion overflow or bad number.
1401
1402 @param thd Thread handler
1403 @param field Field to operate on
1404 @param dec_error decimal library return code
1405 (E_DEC_* see include/decimal.h)
1406 @param [in,out] dec_value Decimal value returned by conversion function.
1407 @param from Value converted from
1408 @param length Length of 'from'
1409 @param charset_arg Charset of 'from'
1410 */
1411 165 static void set_decimal_warning(THD *thd, Field_new_decimal *field,
1412 int dec_error, my_decimal *dec_value,
1413 const char *from, size_t length,
1414 const CHARSET_INFO *charset_arg) {
1415
3/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 123 times.
✗ Branch 3 not taken.
165 switch (dec_error) {
1416 20 case E_DEC_TRUNCATED:
1417
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 field->set_warning(Sql_condition::SL_NOTE, WARN_DATA_TRUNCATED, 1);
1418 42 break;
1419 22 case E_DEC_OVERFLOW:
1420
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 field->set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE,
1421 1);
1422
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 field->set_value_on_overflow(dec_value, dec_value->sign());
1423 22 break;
1424 123 case E_DEC_BAD_NUM:
1425
1/2
✓ Branch 0 taken 123 times.
✗ Branch 1 not taken.
123 ErrConvString errmsg(from, length, charset_arg);
1426 123 const Diagnostics_area *da = thd->get_stmt_da();
1427
2/4
✓ Branch 0 taken 123 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 123 times.
✗ Branch 3 not taken.
123 push_warning_printf(
1428 thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
1429 ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), "decimal",
1430 errmsg.ptr(), field->field_name, da->current_row_for_condition());
1431 123 my_decimal_set_zero(dec_value);
1432 }
1433 165 }
1434
1435 /**
1436 Copy string with optional character set conversion.
1437
1438 This calls helper function well_formed_copy_nchars to copy string
1439 with optional character set conversion. Specially, it checks if
1440 the ASCII code point exceeds code range. If YES, it allows the
1441 input but raises a warning.
1442
1443 @param to_cs Character set of "to" string
1444 @param to Store result here
1445 @param to_length Maximum length of "to" string
1446 @param from_cs From character set
1447 @param from Copy from here
1448 @param from_length Length of from string
1449 @param nchars Copy not more that nchars characters
1450 @param well_formed_error_pos Return position when "from" is not well
1451 formed or NULL otherwise.
1452 @param cannot_convert_error_pos Return position where a not convertible
1453 character met, or NULL otherwise.
1454 @param from_end_pos Return position where scanning of "from"
1455 string stopped.
1456
1457 @retval length of bytes copied to 'to'
1458 */
1459
1460 593335670 static size_t field_well_formed_copy_nchars(
1461 const CHARSET_INFO *to_cs, char *to, size_t to_length,
1462 const CHARSET_INFO *from_cs, const char *from, size_t from_length,
1463 size_t nchars, const char **well_formed_error_pos,
1464 const char **cannot_convert_error_pos, const char **from_end_pos) {
1465 593335670 size_t res = well_formed_copy_nchars(
1466 to_cs, to, to_length, from_cs, from, from_length, nchars,
1467 well_formed_error_pos, cannot_convert_error_pos, from_end_pos);
1468 699422967 return res;
1469 }
1470
1471 /**
1472 Check whether a field type can be partially indexed by a key.
1473
1474 This is a static method, rather than a virtual function, because we need
1475 to check the type of a non-Field in mysql_alter_table().
1476
1477 @param type field type
1478
1479 @retval
1480 true Type can have a prefixed key
1481 @retval
1482 false Type can not have a prefixed key
1483 */
1484
1485 303309 bool Field::type_can_have_key_part(enum enum_field_types type) {
1486
2/2
✓ Branch 0 taken 240450 times.
✓ Branch 1 taken 62859 times.
303309 switch (type) {
1487 240450 case MYSQL_TYPE_VARCHAR:
1488 case MYSQL_TYPE_TINY_BLOB:
1489 case MYSQL_TYPE_MEDIUM_BLOB:
1490 case MYSQL_TYPE_LONG_BLOB:
1491 case MYSQL_TYPE_BLOB:
1492 case MYSQL_TYPE_VAR_STRING:
1493 case MYSQL_TYPE_STRING:
1494 case MYSQL_TYPE_GEOMETRY:
1495 240450 return true;
1496 62859 default:
1497 62859 return false;
1498 }
1499 }
1500
1501 /**
1502 Numeric fields base class constructor.
1503 */
1504 20724732 Field_num::Field_num(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1505 uchar null_bit_arg, uchar auto_flags_arg,
1506 const char *field_name_arg, uint8 dec_arg, bool zero_arg,
1507 20724732 bool unsigned_arg)
1508 : Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
1509 field_name_arg),
1510 20724734 unsigned_flag(unsigned_arg),
1511 20724734 dec(dec_arg),
1512 20724732 zerofill(zero_arg) {
1513
2/2
✓ Branch 0 taken 30832 times.
✓ Branch 1 taken 20693902 times.
20724734 if (zerofill) set_flag(ZEROFILL_FLAG);
1514
2/2
✓ Branch 0 taken 13473487 times.
✓ Branch 1 taken 7251247 times.
20724734 if (unsigned_flag) set_flag(UNSIGNED_FLAG);
1515 20724734 }
1516
1517 80137 void Field_num::prepend_zeros(String *value) const {
1518 int diff;
1519
2/2
✓ Branch 0 taken 27967 times.
✓ Branch 1 taken 52170 times.
80137 if ((diff = (int)(field_length - value->length())) > 0) {
1520 27967 const bool error = value->mem_realloc(field_length);
1521
1/2
✓ Branch 0 taken 27967 times.
✗ Branch 1 not taken.
27967 if (!error) {
1522 27967 memmove(value->ptr() + field_length - value->length(), value->ptr(),
1523 value->length());
1524 27967 memset(value->ptr(), '0', diff);
1525 27967 value->length(field_length);
1526 }
1527 }
1528 80137 }
1529
1530 /**
1531 Test if given number is a int.
1532
1533 @todo
1534 Make this multi-byte-character safe
1535
1536 @param cs Character set
1537 @param str String to test
1538 @param length Length of 'str'
1539 @param int_end Pointer to char after last used digit
1540 @param error Return code from strntoull10rnd()
1541
1542 @note
1543 This is called after one has called strntoull10rnd() function.
1544
1545 @return TYPE_OK, TYPE_ERR_BAD_VALUE or TYPE_WARN_TRUNCATED
1546 */
1547
1548 1210480 type_conversion_status Field_num::check_int(const CHARSET_INFO *cs,
1549 const char *str, size_t length,
1550 const char *int_end, int error) {
1551 /* Test if we get an empty string or wrong integer */
1552
4/4
✓ Branch 0 taken 1210124 times.
✓ Branch 1 taken 356 times.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 1210105 times.
1210480 if (str == int_end || error == MY_ERRNO_EDOM) {
1553
1/2
✓ Branch 0 taken 375 times.
✗ Branch 1 not taken.
375 THD *thd = current_thd;
1554
1/2
✓ Branch 0 taken 375 times.
✗ Branch 1 not taken.
375 ErrConvString err(str, length, cs);
1555
2/4
✓ Branch 0 taken 375 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 375 times.
✗ Branch 3 not taken.
375 push_warning_printf(
1556 thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
1557 ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), "integer", err.ptr(),
1558 field_name, thd->get_stmt_da()->current_row_for_condition());
1559 375 return TYPE_ERR_BAD_VALUE;
1560 }
1561 /* Test if we have garbage at the end of the given string. */
1562
2/2
✓ Branch 0 taken 625 times.
✓ Branch 1 taken 1209480 times.
1210105 if (test_if_important_data(cs, int_end, str + length)) {
1563 625 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
1564 625 return TYPE_WARN_TRUNCATED;
1565 }
1566 1209480 return TYPE_OK;
1567 }
1568
1569 /*
1570 Convert a string to an integer, then check bounds.
1571
1572 SYNOPSIS
1573 Field_num::get_int
1574 cs Character set
1575 from String to convert
1576 len Length of the string
1577 rnd OUT longlong value
1578 unsigned_max max unsigned value
1579 signed_min min signed value
1580 signed_max max signed value
1581
1582 DESCRIPTION
1583 The function calls strntoull10rnd() to get an integer value then
1584 check bounds and errors returned. In case of any error a warning
1585 is raised.
1586
1587 @return TYPE_OK, TYPE_WARN_OUT_OF_RANGE, TYPE_ERR_BAD_VALUE or
1588 TYPE_WARN_TRUNCATED
1589 */
1590
1591 3802480 type_conversion_status Field_num::get_int(const CHARSET_INFO *cs,
1592 const char *from, size_t len,
1593 longlong *rnd, ulonglong unsigned_max,
1594 longlong signed_min,
1595 longlong signed_max) {
1596 const char *end;
1597 int error;
1598
1599
1/2
✓ Branch 0 taken 3802594 times.
✗ Branch 1 not taken.
3802480 *rnd = (longlong)cs->cset->strntoull10rnd(cs, from, len, is_unsigned(), &end,
1600 &error);
1601
2/2
✓ Branch 0 taken 2067330 times.
✓ Branch 1 taken 1735359 times.
3802594 if (is_unsigned()) {
1602
5/6
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 2067313 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
✓ Branch 4 taken 39 times.
✓ Branch 5 taken 2067291 times.
4134643 if ((((ulonglong)*rnd > unsigned_max) && (*rnd = (longlong)unsigned_max)) ||
1603
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2067291 times.
2067313 error == MY_ERRNO_ERANGE)
1604 39 goto out_of_range;
1605 } else {
1606
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 1735343 times.
1735359 if (*rnd < signed_min) {
1607 16 *rnd = signed_min;
1608 16 goto out_of_range;
1609
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 1735320 times.
1735343 } else if (*rnd > signed_max) {
1610 23 *rnd = signed_max;
1611 23 goto out_of_range;
1612 }
1613 }
1614
3/4
✓ Branch 0 taken 3802470 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1089434 times.
✓ Branch 3 taken 2713036 times.
3802611 if (current_thd->check_for_truncated_fields != 0)
1615
1/2
✓ Branch 0 taken 1089434 times.
✗ Branch 1 not taken.
1089434 return check_int(cs, from, len, end, error);
1616
1617 2713036 return TYPE_OK;
1618
1619 78 out_of_range:
1620
1/2
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
78 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
1621 78 return TYPE_WARN_OUT_OF_RANGE;
1622 }
1623
1624 /*
1625 This is a generic method which is executed only for
1626 Field_short, Field_medium, Field_long, Field_longlong and Field_tiny.
1627
1628 The other field types that come from Field_num override this method:
1629 Field_real (common parent for Field_decimal, Field_float, Field_double),
1630 Field_new_decimal, Field_year.
1631 */
1632 6 type_conversion_status Field_num::store_time(MYSQL_TIME *ltime, uint8) {
1633 18 longlong nr = propagate_datetime_overflow(
1634
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 current_thd, [&](int *w) { return TIME_to_ulonglong_round(*ltime, w); });
1635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 return store(ltime->neg ? -nr : nr, false);
1636 }
1637
1638 /**
1639 Process decimal library return codes and issue warnings for overflow and
1640 truncation.
1641
1642 @param op_result decimal library return code (E_DEC_* see include/decimal.h)
1643
1644 @retval 0 No error or some other errors except overflow
1645 @retval 1 There was overflow
1646 */
1647
1648 8216555 bool Field::warn_if_overflow(int op_result) {
1649
2/2
✓ Branch 0 taken 931 times.
✓ Branch 1 taken 8215624 times.
8216555 if (op_result == E_DEC_OVERFLOW) {
1650 931 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
1651 931 return true;
1652 }
1653
2/2
✓ Branch 0 taken 5519 times.
✓ Branch 1 taken 8210105 times.
8215624 if (op_result == E_DEC_TRUNCATED) {
1654 5519 set_warning(Sql_condition::SL_NOTE, WARN_DATA_TRUNCATED, 1);
1655 /* We return 0 here as this is not a critical issue */
1656 }
1657 8215627 return false;
1658 }
1659
1660 /**
1661 Interpret field value as an integer but return the result as a string.
1662
1663 This is used for printing bit_fields as numbers while debugging.
1664 */
1665
1666 2 String *Field::val_int_as_str(String *val_buffer, bool unsigned_val) const {
1667
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 ASSERT_COLUMN_MARKED_FOR_READ;
1668 2 const CHARSET_INFO *cs = &my_charset_bin;
1669 size_t length;
1670 2 longlong value = val_int();
1671
1672
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS)) return nullptr;
1673
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 length = (*cs->cset->longlong10_to_str)(cs, val_buffer->ptr(),
1674 MY_INT64_NUM_DECIMAL_DIGITS,
1675 unsigned_val ? 10 : -10, value);
1676 2 val_buffer->length(length);
1677 2 return val_buffer;
1678 }
1679
1680 /// This is used as a table name when the table structure is not set up
1681 47802130 Field::Field(uchar *ptr_arg, uint32 length_arg, uchar *null_ptr_arg,
1682 uchar null_bit_arg, uchar auto_flags_arg,
1683 47802130 const char *field_name_arg)
1684 47802130 : ptr(ptr_arg),
1685 47802130 m_hidden(dd::Column::enum_hidden_type::HT_VISIBLE),
1686 47802130 m_null_ptr(null_ptr_arg),
1687 47802130 m_is_tmp_nullable(false),
1688 47802130 m_is_tmp_null(false),
1689 47802130 m_check_for_truncated_fields_saved(CHECK_FIELD_IGNORE),
1690 47802130 table(nullptr),
1691 47802130 table_name(nullptr),
1692 47802130 field_name(field_name_arg),
1693 47802151 field_length(length_arg),
1694 47802151 null_bit(null_bit_arg),
1695 47802151 auto_flags(auto_flags_arg),
1696 47802151 is_created_from_null_item(false),
1697 47802151 zip_dict_name(null_lex_cstr),
1698 47802151 zip_dict_data(null_lex_cstr),
1699 47802151 m_indexed(false),
1700 47802151 m_warnings_pushed(0),
1701 47802151 gcol_info(nullptr),
1702 47802151 stored_in_db(true),
1703 47802130 m_default_val_expr(nullptr)
1704
1705 {
1706
2/2
✓ Branch 0 taken 32372936 times.
✓ Branch 1 taken 15429202 times.
47802151 if (!is_nullable()) set_flag(NOT_NULL_FLAG);
1707 47802137 comment.str = "";
1708 47802137 comment.length = 0;
1709 47802137 m_field_index = 0;
1710 47802137 }
1711
1712 /**
1713 Check NOT NULL constraint on the field after temporary nullability is
1714 disabled.
1715
1716 @param mysql_errno Warning to report.
1717
1718 @return TYPE_OK if the value is Ok, or corresponding error code from
1719 the type_conversion_status enum.
1720 */
1721 140193923 type_conversion_status Field::check_constraints(int mysql_errno) {
1722 /*
1723 Ensure that Field::check_constraints() is called only when temporary
1724 nullability is disabled.
1725 */
1726
1727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 140194387 times.
140193923 assert(!is_tmp_nullable());
1728
1729
2/2
✓ Branch 0 taken 89786435 times.
✓ Branch 1 taken 50408091 times.
140194387 if (is_nullable()) return TYPE_OK; // If the field is nullable, we're Ok.
1730
1731
2/2
✓ Branch 0 taken 50407886 times.
✓ Branch 1 taken 205 times.
50408091 if (!m_is_tmp_null) return TYPE_OK; // If the field was not NULL, we're Ok.
1732
1733 // The field has been set to NULL.
1734
1735 /*
1736 If the field is of AUTO_INCREMENT, and the next number
1737 has been assigned to it, we're Ok.
1738 */
1739
1740
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 178 times.
205 if (this == table->next_number_field) return TYPE_OK;
1741
1742
3/4
✓ Branch 0 taken 81 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
178 switch (m_check_for_truncated_fields_saved) {
1743 81 case CHECK_FIELD_WARN:
1744 81 set_warning(Sql_condition::SL_WARNING, mysql_errno, 1);
1745 [[fallthrough]];
1746 81 case CHECK_FIELD_IGNORE:
1747 81 return TYPE_OK;
1748 39 case CHECK_FIELD_ERROR_FOR_NULL:
1749 39 my_error(ER_BAD_NULL_ERROR, MYF(0), field_name);
1750 39 return TYPE_ERR_NULL_CONSTRAINT_VIOLATION;
1751 }
1752
1753 assert(0); // impossible
1754 my_error(ER_BAD_NULL_ERROR, MYF(0), field_name);
1755 return TYPE_ERR_NULL_CONSTRAINT_VIOLATION;
1756 }
1757
1758 /**
1759 Set field to value NULL.
1760
1761 @param row_offset This is the offset between the row being updated
1762 and table->record[0]
1763 */
1764 278947811 void Field::set_null(ptrdiff_t row_offset) {
1765
2/2
✓ Branch 0 taken 278909436 times.
✓ Branch 1 taken 38385 times.
278947811 if (is_nullable()) {
1766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 278909436 times.
278909436 assert(m_null_ptr != &dummy_null_buffer);
1767 278909436 m_null_ptr[row_offset] |= null_bit;
1768
2/2
✓ Branch 0 taken 314 times.
✓ Branch 1 taken 38072 times.
38385 } else if (is_tmp_nullable()) {
1769 314 set_tmp_null();
1770 }
1771 278947822 }
1772
1773 /**
1774 Set field to value NOT NULL.
1775
1776 @param row_offset This is the offset between the row being updated
1777 and table->record[0]
1778 */
1779 947723307 void Field::set_notnull(ptrdiff_t row_offset) {
1780
2/2
✓ Branch 0 taken 502236108 times.
✓ Branch 1 taken 445488489 times.
947723307 if (is_nullable()) {
1781
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 502236108 times.
502236108 assert(m_null_ptr != &dummy_null_buffer);
1782 502236108 m_null_ptr[row_offset] &= (uchar)~null_bit;
1783
2/2
✓ Branch 0 taken 12420901 times.
✓ Branch 1 taken 433068000 times.
445488489 } else if (is_tmp_nullable()) {
1784 12420901 reset_tmp_null();
1785 }
1786 947725009 }
1787
1788 1241241 void Field::hash(ulong *nr, ulong *nr2) const {
1789
2/2
✓ Branch 0 taken 2150 times.
✓ Branch 1 taken 1239092 times.
1241241 if (is_null()) {
1790 2150 *nr ^= (*nr << 1) | 1;
1791 } else {
1792
1/2
✓ Branch 0 taken 1239092 times.
✗ Branch 1 not taken.
1239092 uint len = pack_length();
1793
1/2
✓ Branch 0 taken 1239091 times.
✗ Branch 1 not taken.
1239092 const CHARSET_INFO *cs = sort_charset();
1794 1239091 uint64 tmp1 = *nr;
1795 1239091 uint64 tmp2 = *nr2;
1796
1/2
✓ Branch 0 taken 1239092 times.
✗ Branch 1 not taken.
1239091 cs->coll->hash_sort(cs, ptr, len, &tmp1, &tmp2);
1797
1798 // NOTE: This truncates to 32-bit on Windows, to keep on-disk stability.
1799 1239092 *nr = static_cast<ulong>(tmp1);
1800 1239092 *nr2 = static_cast<ulong>(tmp2);
1801 }
1802 1241242 }
1803
1804 303533 void Field::copy_data(ptrdiff_t src_record_offset) {
1805 303533 memcpy(ptr, ptr + src_record_offset, pack_length());
1806
1807
2/2
✓ Branch 0 taken 111488 times.
✓ Branch 1 taken 192045 times.
303533 if (is_nullable()) {
1808 // Set to NULL if the source record is NULL, otherwise set to NOT-NULL.
1809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111488 times.
111488 assert(m_null_ptr != &dummy_null_buffer);
1810 111488 m_null_ptr[0] = (m_null_ptr[0] & ~null_bit) |
1811 111488 (m_null_ptr[src_record_offset] & null_bit);
1812
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 192039 times.
192045 } else if (is_tmp_nullable())
1813 6 m_is_tmp_null = false;
1814 303533 }
1815
1816 242462457 bool Field::send_to_protocol(Protocol *protocol) const {
1817
4/6
✓ Branch 0 taken 242463107 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16521015 times.
✓ Branch 3 taken 225942092 times.
✓ Branch 4 taken 16521015 times.
✗ Branch 5 not taken.
242462457 if (is_null()) return protocol->store_null();
1818 char buff[MAX_FIELD_WIDTH];
1819
1/2
✓ Branch 0 taken 225942182 times.
✗ Branch 1 not taken.
225942092 String tmp(buff, sizeof(buff), charset());
1820
1/2
✓ Branch 0 taken 225942252 times.
✗ Branch 1 not taken.
225942155 String *res = val_str(&tmp);
1821
2/6
✓ Branch 0 taken 225942252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 225942428 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
225942252 return res ? protocol->store(res) : protocol->store_null();
1822 225942428 }
1823
1824 /**
1825 Checks if the current field definition and provided create field
1826 definition have different compression attributes.
1827
1828 @param new_field create field definition to compare with
1829
1830 @return
1831 true - if compression attributes are different
1832 false - if compression attributes are identical.
1833 */
1834 237062 bool Field::has_different_compression_attributes_with(
1835 const Create_field &new_field) const noexcept {
1836
6/6
✓ Branch 0 taken 237010 times.
✓ Branch 1 taken 52 times.
✓ Branch 2 taken 236995 times.
✓ Branch 3 taken 15 times.
✓ Branch 4 taken 236995 times.
✓ Branch 5 taken 67 times.
474072 if (new_field.column_format() != COLUMN_FORMAT_TYPE_COMPRESSED &&
1837 237010 column_format() != COLUMN_FORMAT_TYPE_COMPRESSED)
1838 236995 return false;
1839
1840
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 31 times.
67 if (new_field.column_format() != column_format()) return true;
1841
1842
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 18 times.
31 if ((zip_dict_name.str == nullptr) &&
1843
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 3 times.
13 (new_field.zip_dict_name.str == nullptr))
1844 10 return false;
1845
1846 21 return !::is_equal(&new_field.zip_dict_name, &zip_dict_name);
1847 }
1848
1849 /**
1850 Check to see if field size is compatible with destination.
1851
1852 This method is used in row-based replication to verify that the
1853 slave's field size is less than or equal to the master's field
1854 size. The encoded field metadata (from the master or source) is
1855 decoded and compared to the size of this field (the slave or
1856 destination).
1857
1858 The comparison is made so that if the source data (from the master)
1859 is less than the target data (on the slave), -1 is returned in
1860 <code>*order_var</code>. This implies that a conversion is
1861 necessary, but that it is lossy and can result in truncation of the
1862 value.
1863
1864 If the source data is strictly greater than the target data, 1 is
1865 returned in <code>*order_var</code>. This implies that the source
1866 type can is contained in the target type and that a conversion is
1867 necessary but is non-lossy.
1868
1869 If no conversion is required to fit the source type in the target
1870 type, 0 is returned in <code>*order_var</code>.
1871
1872 @param field_metadata Encoded size in field metadata
1873 @param order_var Pointer to variable where the order
1874 between the source field and this field
1875 will be returned.
1876
1877 @return @c true if this field's size is compatible with the
1878 master's field size, @c false otherwise.
1879 */
1880 198546 bool Field::compatible_field_size(uint field_metadata, Relay_log_info *, uint16,
1881 int *order_var) const {
1882 198546 uint const source_size = pack_length_from_metadata(field_metadata);
1883 198572 uint const destination_size = row_pack_length();
1884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 198556 times.
198558 DBUG_PRINT("debug", ("real_type: %d, source_size: %u, destination_size: %u",
1885 real_type(), source_size, destination_size));
1886 198556 *order_var = compare(source_size, destination_size);
1887 198549 return true;
1888 }
1889
1890 78153 type_conversion_status Field::store(const char *to, size_t length,
1891 const CHARSET_INFO *cs,
1892 enum_check_fields check_level) {
1893 78153 THD *thd = current_thd;
1894 78153 enum_check_fields old_check_level = thd->check_for_truncated_fields;
1895 78153 thd->check_for_truncated_fields = check_level;
1896 78153 const type_conversion_status res = store(to, length, cs);
1897 78153 thd->check_for_truncated_fields = old_check_level;
1898 78153 return res;
1899 }
1900
1901 4839932 uchar *Field::pack(uchar *to, const uchar *from, size_t max_length) const {
1902 4839932 size_t length = std::min<size_t>(pack_length(), max_length);
1903 4839938 memcpy(to, from, length);
1904 4839938 return to + length;
1905 }
1906
1907 /**
1908 Unpack a field from row data.
1909
1910 This method is used to unpack a field from a master whose size of
1911 the field is less than that of the slave.
1912
1913 The <code>param_data</code> parameter is a two-byte integer (stored
1914 in the least significant 16 bits of the unsigned integer) usually
1915 consisting of two parts: the real type in the most significant byte
1916 and a original pack length in the least significant byte.
1917
1918 The exact layout of the <code>param_data</code> field is given by
1919 the <code>Table_map_log_event::save_field_metadata()</code>.
1920
1921 This is the default method for unpacking a field. It just copies
1922 the memory block in byte order (of original pack length bytes or
1923 length of field, whichever is smaller).
1924
1925 @param to Destination of the data
1926 @param from Source of the data
1927 @param param_data Real type and original pack length of the field
1928 data
1929
1930 @return New pointer into memory based on from + length of the data
1931 */
1932 3057542 const uchar *Field::unpack(uchar *to, const uchar *from, uint param_data) {
1933 3057542 uint length = pack_length();
1934 3057544 int from_type = 0;
1935 /*
1936 If from length is > 255, it has encoded data in the upper bits. Need
1937 to mask it out.
1938 */
1939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3057544 times.
3057544 if (param_data > 255) {
1940 from_type = (param_data & 0xff00) >> 8U; // real_type.
1941 param_data = param_data & 0x00ff; // length.
1942 }
1943
1944
5/6
✓ Branch 0 taken 14883 times.
✓ Branch 1 taken 3042661 times.
✓ Branch 2 taken 1992 times.
✓ Branch 3 taken 12891 times.
✓ Branch 4 taken 3057544 times.
✗ Branch 5 not taken.
3059536 if ((param_data == 0) || (length == param_data) ||
1945
1/2
✓ Branch 0 taken 1992 times.
✗ Branch 1 not taken.
1992 (from_type != real_type())) {
1946 3057544 memcpy(to, from, length);
1947 3057544 return from + length;
1948 }
1949
1950 uint len = (param_data && (param_data < length)) ? param_data : length;
1951
1952 memcpy(to, from, param_data > length ? length : len);
1953 return from + len;
1954 }
1955
1956 /**
1957 Appends the UNSIGNED and ZEROFILL attributes to a String if a Field_num has
1958 these attributes.
1959
1960 @param field the field with the attributes to append
1961 @param[in,out] res the String to append to
1962 */
1963 4434855 static void append_zerofill_and_unsigned(const Field_num *field, String *res) {
1964
2/2
✓ Branch 0 taken 2702426 times.
✓ Branch 1 taken 1732349 times.
4434855 if (field->is_unsigned()) res->append(STRING_WITH_LEN(" unsigned"));
1965
2/2
✓ Branch 0 taken 4856 times.
✓ Branch 1 taken 4429919 times.
4434775 if (field->zerofill) res->append(STRING_WITH_LEN(" zerofill"));
1966 4434775 }
1967
1968 /// Writes an integer type specification to a string.
1969 4118437 static void integer_sql_type(const Field_num *field, const char *type_name,
1970 String *res) {
1971 4118437 res->length(0);
1972
1/2
✓ Branch 0 taken 4118525 times.
✗ Branch 1 not taken.
4118578 res->append(type_name);
1973
2/2
✓ Branch 0 taken 1093 times.
✓ Branch 1 taken 4117432 times.
4118525 if (field->zerofill) res->append_parenthesized(field->field_length);
1974 4118525 append_zerofill_and_unsigned(field, res);
1975 4118491 }
1976
1977 6066942 void Field::make_send_field(Send_field *field) const {
1978
2/2
✓ Branch 0 taken 1752300 times.
✓ Branch 1 taken 4314642 times.
6066942 field->db_name = orig_db_name ? orig_db_name : table->s->db.str;
1979
2/2
✓ Branch 0 taken 1752300 times.
✓ Branch 1 taken 4314642 times.
6066942 field->org_table_name = orig_table_name ? orig_table_name : "";
1980 6066942 field->table_name = table->alias;
1981 6066942 field->org_col_name = field_name;
1982 6066942 field->col_name = field_name;
1983 6066942 field->charsetnr = charset()->number;
1984 6066943 field->length = field_length;
1985 6066943 field->type = type();
1986 6066943 field->flags = all_flags();
1987
2/2
✓ Branch 0 taken 14058 times.
✓ Branch 1 taken 6052885 times.
6066943 if (table->is_nullable()) field->flags &= ~NOT_NULL_FLAG;
1988 6066943 field->decimals = decimals();
1989 6066944 field->field = false;
1990 6066944 }
1991
1992 /**
1993 Conversion from decimal to longlong. Checks overflow and returns
1994 correct value (min/max) in case of overflow.
1995
1996 @param val value to be converted
1997 @param unsigned_flag type of integer to which we convert val
1998 @param has_overflow true if there is overflow
1999
2000 @return
2001 value converted from val
2002 */
2003 2319991 longlong Field::convert_decimal2longlong(const my_decimal *val,
2004 bool unsigned_flag,
2005 bool *has_overflow) {
2006
6/6
✓ Branch 0 taken 1738 times.
✓ Branch 1 taken 2318253 times.
✓ Branch 2 taken 166 times.
✓ Branch 3 taken 1572 times.
✓ Branch 4 taken 166 times.
✓ Branch 5 taken 2319825 times.
2319991 if (unsigned_flag && val->sign()) {
2007 // Converting a signed decimal to unsigned int
2008
1/2
✓ Branch 0 taken 166 times.
✗ Branch 1 not taken.
166 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
2009 166 *has_overflow = true;
2010 166 return 0;
2011 }
2012
2013 longlong val_ll;
2014 int conversion_error =
2015
1/2
✓ Branch 0 taken 2319825 times.
✗ Branch 1 not taken.
2319825 my_decimal2int(E_DEC_ERROR & ~E_DEC_OVERFLOW & ~E_DEC_TRUNCATED, val,
2016 unsigned_flag, &val_ll);
2017
2018
3/4
✓ Branch 0 taken 2319825 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 352 times.
✓ Branch 3 taken 2319473 times.
2319825 if (warn_if_overflow(conversion_error)) {
2019 352 *has_overflow = true;
2020
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 224 times.
352 if (unsigned_flag) return ULLONG_MAX;
2021
2022
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 66 times.
224 return (val->sign() ? LLONG_MIN : LLONG_MAX);
2023 }
2024
2025 2319473 return val_ll;
2026 }
2027
2028 /**
2029 Storing decimal in integer fields.
2030
2031 @param val value for storing
2032
2033 @note
2034 This method is used by all integer fields, real/decimal redefine it
2035
2036 @retval TYPE_OK Storage of value went fine without warnings or errors
2037 @retval !TYPE_OK Warning/error as indicated by type_conversion_status enum
2038 value
2039 */
2040 2319991 type_conversion_status Field_num::store_decimal(const my_decimal *val) {
2041
4/6
✓ Branch 0 taken 2319991 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2319948 times.
✓ Branch 3 taken 43 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2319948 times.
2319991 ASSERT_COLUMN_MARKED_FOR_WRITE;
2042 2319991 bool has_overflow = false;
2043
1/2
✓ Branch 0 taken 2319991 times.
✗ Branch 1 not taken.
2319991 longlong i = convert_decimal2longlong(val, is_unsigned(), &has_overflow);
2044
1/2
✓ Branch 0 taken 2319991 times.
✗ Branch 1 not taken.
2319991 const type_conversion_status res = store(i, is_unsigned());
2045
2/2
✓ Branch 0 taken 518 times.
✓ Branch 1 taken 2319473 times.
2319991 return has_overflow ? TYPE_WARN_OUT_OF_RANGE : res;
2046 }
2047
2048 /**
2049 Return decimal value of integer field.
2050
2051 @param decimal_value buffer for storing decimal value
2052
2053 @note
2054 This method is used by all integer fields, real/decimal redefine it.
2055 All longlong values fit in our decimal buffer which cal store 8*9=72
2056 digits of integer number
2057
2058 @return
2059 pointer to decimal buffer with value of field
2060 */
2061
2062 40140418 my_decimal *Field_num::val_decimal(my_decimal *decimal_value) const {
2063
4/6
✓ Branch 0 taken 40140419 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40139409 times.
✓ Branch 3 taken 1010 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 40139412 times.
40140418 ASSERT_COLUMN_MARKED_FOR_READ;
2064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40140421 times.
40140421 assert(result_type() == INT_RESULT);
2065 40140421 longlong nr = val_int();
2066 40140423 int2my_decimal(E_DEC_FATAL_ERROR, nr, is_unsigned(), decimal_value);
2067 40140421 return decimal_value;
2068 }
2069
2070 124 bool Field_num::get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const {
2071
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 124 times.
124 assert(result_type() == INT_RESULT);
2072 124 return my_longlong_to_datetime_with_warn(val_int(), ltime, fuzzydate);
2073 }
2074
2075 56 bool Field_num::get_time(MYSQL_TIME *ltime) const {
2076
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 assert(result_type() == INT_RESULT);
2077 56 return my_longlong_to_time_with_warn(val_int(), ltime);
2078 }
2079
2080 24934043 Field_str::Field_str(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2081 uchar null_bit_arg, uchar auto_flags_arg,
2082 const char *field_name_arg,
2083 24934043 const CHARSET_INFO *charset_arg)
2084 : Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2085 24934043 field_name_arg) {
2086 24934048 field_charset = charset_arg;
2087
2/2
✓ Branch 0 taken 11872447 times.
✓ Branch 1 taken 13061601 times.
24934048 if (charset_arg->state & MY_CS_BINSORT) set_flag(BINARY_FLAG);
2088 24934049 field_derivation = DERIVATION_IMPLICIT;
2089
1/2
✓ Branch 0 taken 24934043 times.
✗ Branch 1 not taken.
24934049 char_length_cache = char_length();
2090 24934043 }
2091
2092 4261898 void Field_str::make_send_field(Send_field *field) const {
2093 4261898 Field::make_send_field(field);
2094 4261899 field->decimals = 0;
2095 4261899 }
2096
2097 /**
2098 Decimal representation of Field_str.
2099
2100 @param d value for storing
2101
2102 @note
2103 Field_str is the base class for fields implementing
2104 [VAR]CHAR, VAR[BINARY], BLOB/TEXT, GEOMETRY, JSON.
2105 String value should be converted to floating point value according
2106 our rules, so we use double to store value of decimal in string.
2107
2108 @todo
2109 use decimal2string?
2110
2111 @retval
2112 0 OK
2113 @retval
2114 !=0 error
2115 */
2116
2117 1 type_conversion_status Field_str::store_decimal(const my_decimal *d) {
2118
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 ASSERT_COLUMN_MARKED_FOR_WRITE;
2119 double val;
2120 /* TODO: use decimal2string? */
2121
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 int err = my_decimal2double(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, d, &val);
2122
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 warn_if_overflow(err);
2123
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 const type_conversion_status res = store(val);
2124
2125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 return (err != E_DEC_OK) ? decimal_err_to_type_conv_status(err) : res;
2126 }
2127
2128 696 bool Field::get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const {
2129 char buff[MAX_DATE_STRING_REP_LENGTH];
2130 696 String tmp(buff, sizeof(buff), &my_charset_bin), *res;
2131
2/4
✓ Branch 0 taken 696 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 696 times.
✗ Branch 3 not taken.
1392 return !(res = val_str(&tmp)) ||
2132
3/4
✓ Branch 0 taken 696 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 219 times.
✓ Branch 3 taken 477 times.
1392 str_to_datetime_with_warn(res, ltime, fuzzydate);
2133 696 }
2134
2135 144 bool Field::get_time(MYSQL_TIME *ltime) const {
2136 char buff[MAX_DATE_STRING_REP_LENGTH];
2137 144 String tmp(buff, sizeof(buff), &my_charset_bin), *res;
2138
5/8
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 144 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 82 times.
✓ Branch 7 taken 62 times.
288 return !(res = val_str(&tmp)) || str_to_time_with_warn(res, ltime);
2139 144 }
2140
2141 162 bool Field::get_timestamp(my_timeval *tm, int *warnings) const {
2142 MYSQL_TIME ltime;
2143
2/4
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 162 times.
162 assert(!is_null());
2144
3/4
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 159 times.
✓ Branch 3 taken 3 times.
321 return get_date(&ltime, TIME_FUZZY_DATE) ||
2145
4/6
✓ Branch 0 taken 159 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 159 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 143 times.
321 datetime_to_timeval(&ltime, *current_thd->time_zone(), tm, warnings);
2146 }
2147
2148 /**
2149 This is called when storing a date in a string.
2150
2151 @note
2152 Needs to be changed if/when we want to support different time formats.
2153 */
2154
2155 210 type_conversion_status Field::store_time(MYSQL_TIME *ltime, uint8 dec_arg) {
2156
3/6
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 210 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 210 times.
210 ASSERT_COLUMN_MARKED_FOR_WRITE;
2157 char buff[MAX_DATE_STRING_REP_LENGTH];
2158 420 uint length = my_TIME_to_str(*ltime, buff,
2159
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 std::min(dec_arg, uint8{DATETIME_MAX_DECIMALS}));
2160 /* Avoid conversion when field character set is ASCII compatible */
2161
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 return store(
2162 buff, length,
2163
4/6
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 196 times.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 196 times.
✗ Branch 5 not taken.
630 (charset()->state & MY_CS_NONASCII) ? &my_charset_latin1 : charset());
2164 }
2165
2166 11195817 bool Field::optimize_range(uint idx, uint part) const {
2167 11195817 return table->file->index_flags(idx, part, true) & HA_READ_RANGE;
2168 }
2169
2170 5551808 Field *Field::new_field(MEM_ROOT *root, TABLE *new_table) const {
2171 5551808 Field *tmp = clone(root);
2172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5551849 times.
5551849 if (tmp == nullptr) return nullptr;
2173
2174
5/6
✓ Branch 0 taken 5551919 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 892795 times.
✓ Branch 3 taken 4659124 times.
✓ Branch 4 taken 892796 times.
✓ Branch 5 taken 4659053 times.
5551849 if (tmp->table && tmp->table->is_nullable()) tmp->clear_flag(NOT_NULL_FLAG);
2175 5551843 tmp->table = new_table;
2176 5551843 tmp->key_start.init(0);
2177 5551935 tmp->part_of_key.init(0);
2178 5551980 tmp->part_of_prefixkey.init(0);
2179 5551977 tmp->part_of_sortkey.init(0);
2180 5551979 tmp->m_indexed = false;
2181 // Set original db & table name, unless already copied from the old field
2182
4/4
✓ Branch 0 taken 5411149 times.
✓ Branch 1 taken 140830 times.
✓ Branch 2 taken 5301807 times.
✓ Branch 3 taken 109342 times.
5551979 if (tmp->orig_db_name == nullptr && table->pos_in_table_list != nullptr)
2183 5301807 tmp->orig_db_name = table->pos_in_table_list->db;
2184
4/4
✓ Branch 0 taken 5411156 times.
✓ Branch 1 taken 140823 times.
✓ Branch 2 taken 5301822 times.
✓ Branch 3 taken 109334 times.
5551979 if (tmp->orig_table_name == nullptr && table->pos_in_table_list != nullptr)
2185 5301822 tmp->orig_table_name = table->pos_in_table_list->table_name;
2186 /*
2187 todo: We should never alter auto_flags after an object is constructed,
2188 and the member should be made const. But a lot of code depends upon this
2189 hack, and some flags are completely unrelated so we can never be quite
2190 sure which parts of the server will break.
2191 */
2192 5551979 tmp->auto_flags = Field::NONE;
2193 /* COMPRESSED column format flag must not be cleared here */
2194 const bool has_compressed_flag =
2195 5551979 (tmp->column_format() == COLUMN_FORMAT_TYPE_COMPRESSED);
2196 5551984 tmp->flags &= (NOT_NULL_FLAG | BLOB_FLAG | UNSIGNED_FLAG | ZEROFILL_FLAG |
2197 BINARY_FLAG | ENUM_FLAG | SET_FLAG | NOT_SECONDARY_FLAG);
2198
2/2
✓ Branch 0 taken 204 times.
✓ Branch 1 taken 5551780 times.
5551984 if (has_compressed_flag)
2199 204 tmp->set_column_format(COLUMN_FORMAT_TYPE_COMPRESSED);
2200 5551992 return tmp;
2201 }
2202
2203 2498456 Field *Field::new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr,
2204 uchar *new_null_ptr, uint new_null_bit) const {
2205 2498456 Field *tmp = new_field(root, new_table);
2206
1/2
✓ Branch 0 taken 2498700 times.
✗ Branch 1 not taken.
2498668 if (tmp != nullptr) {
2207 2498700 tmp->ptr = new_ptr;
2208 2498700 tmp->m_null_ptr = new_null_ptr;
2209 2498700 tmp->null_bit = new_null_bit;
2210 }
2211 2498668 return tmp;
2212 }
2213
2214 3926869 void Field::evaluate_insert_default_function() {
2215
2/2
✓ Branch 0 taken 3926421 times.
✓ Branch 1 taken 448 times.
3926869 if (has_insert_default_datetime_value_expression())
2216 3926421 Item_func_now_local::store_in(this);
2217 // evaluate and store the values generated by default expression
2218
2/2
✓ Branch 0 taken 447 times.
✓ Branch 1 taken 1 times.
448 else if (has_insert_default_general_value_expression())
2219 447 m_default_val_expr->expr_item->save_in_field(this, false);
2220 3926869 }
2221
2222 142160 void Field::evaluate_update_default_function() {
2223
2/2
✓ Branch 0 taken 142159 times.
✓ Branch 1 taken 1 times.
142160 if (has_update_default_datetime_value_expression())
2224 142159 Item_func_now_local::store_in(this);
2225 142160 }
2226
2227 /****************************************************************************
2228 Field_null, a field that always return NULL
2229 ****************************************************************************/
2230
2231 void Field_null::sql_type(String &res) const {
2232 res.set_ascii(STRING_WITH_LEN("null"));
2233 }
2234
2235 /****************************************************************************
2236 Functions for the Field_decimal class
2237 This is an number stored as a pre-space (or pre-zero) string
2238 ****************************************************************************/
2239
2240 void Field_decimal::overflow(bool negative) {
2241 uint len = field_length;
2242 uchar *to = ptr, filler = '9';
2243
2244 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
2245 if (negative) {
2246 if (!is_unsigned()) {
2247 /* Put - sign as a first digit so we'll have -999..999 or 999..999 */
2248 *to++ = '-';
2249 len--;
2250 } else {
2251 filler = '0'; // Fill up with 0
2252 if (!zerofill) {
2253 /*
2254 Handle unsigned integer without zerofill, in which case
2255 the number should be of format ' 0' or ' 0.000'
2256 */
2257 uint whole_part = field_length - (dec ? dec + 2 : 1);
2258 // Fill with spaces up to the first digit
2259 memset(to, ' ', whole_part);
2260 to += whole_part;
2261 len -= whole_part;
2262 // The main code will also handle the 0 before the decimal point
2263 }
2264 }
2265 }
2266 memset(to, filler, len);
2267 if (dec) ptr[field_length - dec - 1] = '.';
2268 return;
2269 }
2270
2271 type_conversion_status Field_decimal::store(const char *from_arg, size_t len,
2272 const CHARSET_INFO *cs) {
2273 ASSERT_COLUMN_MARKED_FOR_WRITE;
2274 char buff[STRING_BUFFER_USUAL_SIZE];
2275 String tmp(buff, sizeof(buff), &my_charset_bin);
2276 const uchar *from = pointer_cast<const uchar *>(from_arg);
2277
2278 THD *thd = current_thd;
2279
2280 /* Convert character set if the old one is multi uchar */
2281 if (cs->mbmaxlen > 1) {
2282 uint dummy_errors;
2283 tmp.copy(from_arg, len, cs, &my_charset_bin, &dummy_errors);
2284 from = (uchar *)tmp.ptr();
2285 len = tmp.length();
2286 }
2287
2288 const uchar *end = from + len;
2289 /* The pointer where the field value starts (i.e., "where to write") */
2290 uchar *to = ptr;
2291 uint tmp_dec, tmp_uint;
2292 /*
2293 The sign of the number : will be 0 (means positive but sign not
2294 specified), '+' or '-'
2295 */
2296 uchar sign_char = 0;
2297 /* The pointers where prezeros start and stop */
2298 const uchar *pre_zeros_from, *pre_zeros_end;
2299 /* The pointers where digits at the left of '.' start and stop */
2300 const uchar *int_digits_from, *int_digits_end;
2301 /* The pointers where digits at the right of '.' start and stop */
2302 const uchar *frac_digits_from, *frac_digits_end;
2303 /* The sign of the exponent : will be 0 (means no exponent), '+' or '-' */
2304 char expo_sign_char = 0;
2305 uint exponent = 0; // value of the exponent
2306 /*
2307 Pointers used when digits move from the left of the '.' to the
2308 right of the '.' (explained below)
2309 */
2310 const uchar *int_digits_tail_from = nullptr;
2311 /* Number of 0 that need to be added at the left of the '.' (1E3: 3 zeros) */
2312 uint int_digits_added_zeros = 0;
2313 /*
2314 Pointer used when digits move from the right of the '.' to the left
2315 of the '.'
2316 */
2317 const uchar *frac_digits_head_end = nullptr;
2318 /* Number of 0 that need to be added at the right of the '.' (for 1E-3) */
2319 uint frac_digits_added_zeros = 0;
2320 uchar *pos, *tmp_left_pos, *tmp_right_pos;
2321 /* Pointers that are used as limits (begin and end of the field buffer) */
2322 uchar *left_wall, *right_wall;
2323 uchar tmp_char;
2324 /*
2325 To remember if thd->num_truncated_fields has already
2326 been incremented, to do that only once
2327 */
2328 bool has_incremented_num_truncated_fields = false;
2329
2330 /*
2331 There are three steps in this function :
2332 - parse the input string
2333 - modify the position of digits around the decimal dot '.'
2334 according to the exponent value (if specified)
2335 - write the formatted number
2336 */
2337
2338 if ((tmp_dec = dec)) tmp_dec++;
2339
2340 /* skip pre-space */
2341 while (from != end && my_isspace(&my_charset_bin, *from)) from++;
2342 if (from == end) {
2343 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
2344 has_incremented_num_truncated_fields = true;
2345 } else if (*from == '+' || *from == '-') // Found some sign ?
2346 {
2347 sign_char = *from++;
2348 /*
2349 We allow "+" for unsigned decimal unless defined different
2350 Both options allowed as one may wish not to have "+" for unsigned numbers
2351 because of data processing issues
2352 */
2353 if (is_unsigned()) {
2354 if (sign_char == '-') {
2355 Field_decimal::overflow(true);
2356 return TYPE_WARN_OUT_OF_RANGE;
2357 }
2358 }
2359 }
2360
2361 pre_zeros_from = from;
2362 for (; from != end && *from == '0'; from++)
2363 ; // Read prezeros
2364 pre_zeros_end = int_digits_from = from;
2365 /* Read non zero digits at the left of '.'*/
2366 for (; from != end && my_isdigit(&my_charset_bin, *from); from++)
2367 ;
2368 int_digits_end = from;
2369 if (from != end && *from == '.') // Some '.' ?
2370 from++;
2371 frac_digits_from = from;
2372 /* Read digits at the right of '.' */
2373 for (; from != end && my_isdigit(&my_charset_bin, *from); from++)
2374 ;
2375 frac_digits_end = from;
2376 // Some exponentiation symbol ?
2377 if (from != end && (*from == 'e' || *from == 'E')) {
2378 from++;
2379 if (from != end && (*from == '+' || *from == '-')) // Some exponent sign ?
2380 expo_sign_char = *from++;
2381 else
2382 expo_sign_char = '+';
2383 /*
2384 Read digits of the exponent and compute its value. We must care about
2385 'exponent' overflow, because as unsigned arithmetic is "modulo", big
2386 exponents will become small (e.g. 1e4294967296 will become 1e0, and the
2387 field will finally contain 1 instead of its max possible value).
2388 */
2389 for (; from != end && my_isdigit(&my_charset_bin, *from); from++) {
2390 exponent = 10 * exponent + (*from - '0');
2391 if (exponent > MAX_EXPONENT) break;
2392 }
2393 }
2394
2395 /*
2396 We only have to generate warnings if check_for_truncated_fields is set.
2397 This is to avoid extra checks of the number when they are not needed.
2398 Even if this flag is not set, it's OK to increment warnings, if
2399 it makes the code easier to read.
2400 */
2401
2402 if (thd->check_for_truncated_fields) {
2403 // Skip end spaces
2404 for (; from != end && my_isspace(&my_charset_bin, *from); from++)
2405 ;
2406 if (from != end) // If still something left, warn
2407 {
2408 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
2409 has_incremented_num_truncated_fields = true;
2410 }
2411 }
2412
2413 /*
2414 Now "move" digits around the decimal dot according to the exponent value,
2415 and add necessary zeros.
2416 Examples :
2417 - 1E+3 : needs 3 more zeros at the left of '.' (int_digits_added_zeros=3)
2418 - 1E-3 : '1' moves at the right of '.', and 2 more zeros are needed
2419 between '.' and '1'
2420 - 1234.5E-3 : '234' moves at the right of '.'
2421 These moves are implemented with pointers which point at the begin
2422 and end of each moved segment. Examples :
2423 - 1234.5E-3 : before the code below is executed, the int_digits part is
2424 from '1' to '4' and the frac_digits part from '5' to '5'. After the code
2425 below, the int_digits part is from '1' to '1', the frac_digits_head
2426 part is from '2' to '4', and the frac_digits part from '5' to '5'.
2427 - 1234.5E3 : before the code below is executed, the int_digits part is
2428 from '1' to '4' and the frac_digits part from '5' to '5'. After the code
2429 below, the int_digits part is from '1' to '4', the int_digits_tail
2430 part is from '5' to '5', the frac_digits part is empty, and
2431 int_digits_added_zeros=2 (to make 1234500).
2432 */
2433
2434 /*
2435 Below tmp_uint cannot overflow with small enough MAX_EXPONENT setting,
2436 as int_digits_added_zeros<=exponent<4G and
2437 (int_digits_end-int_digits_from)<=max_allowed_packet<=2G and
2438 (frac_digits_from-int_digits_tail_from)<=max_allowed_packet<=2G
2439 */
2440
2441 if (!expo_sign_char)
2442 tmp_uint = tmp_dec + (uint)(int_digits_end - int_digits_from);
2443 else if (expo_sign_char == '-') {
2444 tmp_uint = min(exponent, (uint)(int_digits_end - int_digits_from));
2445 frac_digits_added_zeros = exponent - tmp_uint;
2446 int_digits_end -= tmp_uint;
2447 frac_digits_head_end = int_digits_end + tmp_uint;
2448 tmp_uint = tmp_dec + (uint)(int_digits_end - int_digits_from);
2449 } else // (expo_sign_char=='+')
2450 {
2451 tmp_uint = min(exponent, (uint)(frac_digits_end - frac_digits_from));
2452 int_digits_added_zeros = exponent - tmp_uint;
2453 int_digits_tail_from = frac_digits_from;
2454 frac_digits_from = frac_digits_from + tmp_uint;
2455 /*
2456 We "eat" the heading zeros of the
2457 int_digits.int_digits_tail.int_digits_added_zeros concatenation
2458 (for example 0.003e3 must become 3 and not 0003)
2459 */
2460 if (int_digits_from == int_digits_end) {
2461 /*
2462 There was nothing in the int_digits part, so continue
2463 eating int_digits_tail zeros
2464 */
2465 for (; int_digits_tail_from != frac_digits_from &&
2466 *int_digits_tail_from == '0';
2467 int_digits_tail_from++)
2468 ;
2469 if (int_digits_tail_from == frac_digits_from) {
2470 // there were only zeros in int_digits_tail too
2471 int_digits_added_zeros = 0;
2472 }
2473 }
2474 tmp_uint = (uint)(tmp_dec + (int_digits_end - int_digits_from) +
2475 (uint)(frac_digits_from - int_digits_tail_from) +
2476 int_digits_added_zeros);
2477 }
2478
2479 /*
2480 Now write the formatted number
2481
2482 First the digits of the int_% parts.
2483 Do we have enough room to write these digits ?
2484 If the sign is defined and '-', we need one position for it
2485 */
2486
2487 if (field_length < tmp_uint + (int)(sign_char == '-')) {
2488 // too big number, change to max or min number
2489 Field_decimal::overflow(sign_char == '-');
2490 return TYPE_WARN_OUT_OF_RANGE;
2491 }
2492
2493 /*
2494 Tmp_left_pos is the position where the leftmost digit of
2495 the int_% parts will be written
2496 */
2497 tmp_left_pos = pos = to + (uint)(field_length - tmp_uint);
2498
2499 // Write all digits of the int_% parts
2500 while (int_digits_from != int_digits_end) *pos++ = *int_digits_from++;
2501
2502 if (expo_sign_char == '+') {
2503 while (int_digits_tail_from != frac_digits_from)
2504 *pos++ = *int_digits_tail_from++;
2505 while (int_digits_added_zeros-- > 0) *pos++ = '0';
2506 }
2507 /*
2508 Note the position where the rightmost digit of the int_% parts has been
2509 written (this is to later check if the int_% parts contained nothing,
2510 meaning an extra 0 is needed).
2511 */
2512 tmp_right_pos = pos;
2513
2514 /*
2515 Step back to the position of the leftmost digit of the int_% parts,
2516 to write sign and fill with zeros or blanks or prezeros.
2517 */
2518 pos = tmp_left_pos - 1;
2519 if (zerofill) {
2520 left_wall = to - 1;
2521 while (pos > left_wall) // Fill with zeros
2522 *pos-- = '0';
2523 } else {
2524 left_wall = to + (sign_char != 0) - 1;
2525 if (!expo_sign_char) // If exponent was specified, ignore prezeros
2526 {
2527 for (; pos > left_wall && pre_zeros_from != pre_zeros_end;
2528 pre_zeros_from++)
2529 *pos-- = '0';
2530 }
2531 if (pos == tmp_right_pos - 1)
2532 *pos-- = '0'; // no 0 has ever been written, so write one
2533 left_wall = to - 1;
2534 if (sign_char && pos != left_wall) {
2535 /* Write sign if possible (it is if sign is '-') */
2536 *pos-- = sign_char;
2537 }
2538 while (pos != left_wall) *pos-- = ' '; // fill with blanks
2539 }
2540
2541 /*
2542 Write digits of the frac_% parts ;
2543 Depending on thd->check_for_truncated_fields, we may also want
2544 to know if some non-zero tail of these parts will
2545 be truncated (for example, 0.002->0.00 will generate a warning,
2546 while 0.000->0.00 will not)
2547 (and 0E1000000000 will not, while 1E-1000000000 will)
2548 */
2549
2550 pos = to + (uint)(field_length - tmp_dec); // Calculate post to '.'
2551 right_wall = to + field_length;
2552 if (pos != right_wall) *pos++ = '.';
2553
2554 if (expo_sign_char == '-') {
2555 while (frac_digits_added_zeros-- > 0) {
2556 if (pos == right_wall) {
2557 if (thd->check_for_truncated_fields &&
2558 !has_incremented_num_truncated_fields)
2559 break; // Go on below to see if we lose non zero digits
2560 return TYPE_OK;
2561 }
2562 *pos++ = '0';
2563 }
2564 while (int_digits_end != frac_digits_head_end) {
2565 tmp_char = *int_digits_end++;
2566 if (pos == right_wall) {
2567 if (tmp_char != '0') // Losing a non zero digit ?
2568 {
2569 if (!has_incremented_num_truncated_fields)
2570 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
2571 return TYPE_OK;
2572 }
2573 continue;
2574 }
2575 *pos++ = tmp_char;
2576 }
2577 }
2578
2579 for (; frac_digits_from != frac_digits_end;) {
2580 tmp_char = *frac_digits_from++;
2581 if (pos == right_wall) {
2582 if (tmp_char != '0') // Losing a non zero digit ?
2583 {
2584 if (!has_incremented_num_truncated_fields) {
2585 /*
2586 This is a note, not a warning, as we don't want to abort
2587 when we cut decimals in strict mode
2588 */
2589 set_warning(Sql_condition::SL_NOTE, WARN_DATA_TRUNCATED, 1);
2590 }
2591 return TYPE_OK;
2592 }
2593 continue;
2594 }
2595 *pos++ = tmp_char;
2596 }
2597
2598 while (pos != right_wall) *pos++ = '0'; // Fill with zeros at right of '.'
2599 return TYPE_OK;
2600 }
2601
2602 type_conversion_status Field_decimal::store(double nr) {
2603 ASSERT_COLUMN_MARKED_FOR_WRITE;
2604 if (is_unsigned() && nr < 0) {
2605 overflow(true);
2606 return TYPE_WARN_OUT_OF_RANGE;
2607 }
2608
2609 if (!std::isfinite(nr)) // Handle infinity as special case
2610 {
2611 overflow(nr < 0.0);
2612 return TYPE_WARN_OUT_OF_RANGE;
2613 }
2614
2615 size_t i;
2616 size_t length;
2617 uchar fyllchar, *to;
2618 char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
2619
2620 fyllchar = zerofill ? '0' : ' ';
2621 length = my_fcvt(nr, dec, buff, nullptr);
2622
2623 if (length > field_length) {
2624 overflow(nr < 0.0);
2625 return TYPE_WARN_OUT_OF_RANGE;
2626 } else {
2627 to = ptr;
2628 for (i = field_length - length; i-- > 0;) *to++ = fyllchar;
2629 memcpy(to, buff, length);
2630 return TYPE_OK;
2631 }
2632 }
2633
2634 type_conversion_status Field_decimal::store(longlong nr, bool unsigned_val) {
2635 ASSERT_COLUMN_MARKED_FOR_WRITE;
2636 char buff[22];
2637 uint length, int_part;
2638 char fyllchar;
2639 uchar *to;
2640
2641 if (nr < 0 && is_unsigned() && !unsigned_val) {
2642 overflow(true);
2643 return TYPE_WARN_OUT_OF_RANGE;
2644 }
2645 length = (uint)(longlong10_to_str(nr, buff, unsigned_val ? 10 : -10) - buff);
2646 int_part = field_length - (dec ? dec + 1 : 0);
2647
2648 if (length > int_part) {
2649 overflow(!unsigned_val && nr < 0L); /* purecov: inspected */
2650 return TYPE_WARN_OUT_OF_RANGE;
2651 }
2652
2653 fyllchar = zerofill ? '0' : ' ';
2654 to = ptr;
2655 for (uint i = int_part - length; i-- > 0;) *to++ = fyllchar;
2656 memcpy(to, buff, length);
2657 if (dec) {
2658 to[length] = '.';
2659 memset(to + length + 1, '0', dec);
2660 }
2661 return TYPE_OK;
2662 }
2663
2664 double Field_decimal::val_real() const {
2665 ASSERT_COLUMN_MARKED_FOR_READ;
2666 int not_used;
2667 const char *end_not_used;
2668 return my_strntod(&my_charset_bin, pointer_cast<const char *>(ptr),
2669 field_length, &end_not_used, &not_used);
2670 }
2671
2672 longlong Field_decimal::val_int() const {
2673 ASSERT_COLUMN_MARKED_FOR_READ;
2674 int not_used;
2675 if (is_unsigned())
2676 return my_strntoull(&my_charset_bin, pointer_cast<const char *>(ptr),
2677 field_length, 10, NULL, &not_used);
2678 return my_strntoll(&my_charset_bin, pointer_cast<const char *>(ptr),
2679 field_length, 10, NULL, &not_used);
2680 }
2681
2682 String *Field_decimal::val_str(String *, String *val_ptr) const {
2683 ASSERT_COLUMN_MARKED_FOR_READ;
2684 const uchar *str;
2685 size_t tmp_length;
2686
2687 for (str = ptr; *str == ' '; str++)
2688 ;
2689 val_ptr->set_charset(&my_charset_numeric);
2690 tmp_length = (size_t)(str - ptr);
2691 if (field_length < tmp_length) // Error in data
2692 val_ptr->length(0);
2693 else
2694 val_ptr->set_ascii(pointer_cast<const char *>(str),
2695 field_length - tmp_length);
2696 return val_ptr;
2697 }
2698
2699 /**
2700 Should be able to handle at least the following fixed decimal formats:
2701 5.00 , -1.0, 05, -05, +5 with optional pre/end space
2702 */
2703
2704 int Field_decimal::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
2705 const uchar *end;
2706 int swap = 0;
2707 /* First remove prefixes '0', ' ', and '-' */
2708 for (end = a_ptr + field_length;
2709 a_ptr != end &&
2710 (*a_ptr == *b_ptr || ((my_isspace(&my_charset_bin, *a_ptr) ||
2711 *a_ptr == '+' || *a_ptr == '0') &&
2712 (my_isspace(&my_charset_bin, *b_ptr) ||
2713 *b_ptr == '+' || *b_ptr == '0')));
2714 a_ptr++, b_ptr++) {
2715 if (*a_ptr == '-') // If both numbers are negative
2716 swap = -1 ^ 1; // Swap result
2717 }
2718 if (a_ptr == end) return 0;
2719 if (*a_ptr == '-') return -1;
2720 if (*b_ptr == '-') return 1;
2721
2722 while (a_ptr != end) {
2723 if (*a_ptr++ != *b_ptr++)
2724 return swap ^ (a_ptr[-1] < b_ptr[-1] ? -1 : 1); // compare digits
2725 }
2726 return 0;
2727 }
2728
2729 65 size_t Field_decimal::make_sort_key(uchar *to, size_t length) const {
2730 uchar *str, *end;
2731 65 for (str = ptr, end = ptr + length;
2732
1/2
✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
65 str != end &&
2733
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 65 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 65 times.
65 ((my_isspace(&my_charset_bin, *str) || *str == '+' || *str == '0'));
2734 str++)
2735 *to++ = ' ';
2736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 65 times.
65 if (str == end) return length; /* purecov: inspected */
2737
2738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 65 times.
65 if (*str == '-') {
2739 *to++ = 1; // Smaller than any number
2740 str++;
2741 while (str != end)
2742 if (my_isdigit(&my_charset_bin, *str))
2743 *to++ = (char)('9' - *str++);
2744 else
2745 *to++ = *str++;
2746 } else
2747 65 memcpy(to, str, (uint)(end - str));
2748 65 return length;
2749 }
2750
2751 1023 void Field_decimal::sql_type(String &res) const {
2752 1023 const CHARSET_INFO *cs = res.charset();
2753 1023 uint tmp = field_length;
2754
1/2
✓ Branch 0 taken 1023 times.
✗ Branch 1 not taken.
1023 if (!is_unsigned()) tmp--;
2755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1023 times.
1023 if (dec) tmp--;
2756 1023 res.length(cs->cset->snprintf(cs, res.ptr(), res.alloced_length(),
2757 1023 "decimal(%d,%d)", tmp, dec));
2758 1023 append_zerofill_and_unsigned(this, &res);
2759 1023 }
2760
2761 /****************************************************************************
2762 ** Field_new_decimal
2763 ****************************************************************************/
2764
2765 731409 Field_new_decimal::Field_new_decimal(uchar *ptr_arg, uint32 len_arg,
2766 uchar *null_ptr_arg, uchar null_bit_arg,
2767 uchar auto_flags_arg,
2768 const char *field_name_arg, uint8 dec_arg,
2769 731409 bool zero_arg, bool unsigned_arg)
2770 : Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2771 731409 field_name_arg, dec_arg, zero_arg, unsigned_arg) {
2772 731414 precision =
2773 731413 std::min(my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg),
2774 731413 uint(DECIMAL_MAX_PRECISION));
2775
3/4
✓ Branch 0 taken 731414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 731413 times.
✓ Branch 3 taken 1 times.
731414 assert((precision <= DECIMAL_MAX_PRECISION) && (dec <= DECIMAL_MAX_SCALE));
2776
1/2
✓ Branch 0 taken 731413 times.
✗ Branch 1 not taken.
731413 bin_size = my_decimal_get_binary_size(precision, dec);
2777 731413 }
2778
2779 337508 Field_new_decimal::Field_new_decimal(uint32 len_arg, bool is_nullable_arg,
2780 const char *name, uint8 dec_arg,
2781 337508 bool unsigned_arg)
2782 : Field_num(nullptr, len_arg,
2783 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE, name,
2784
2/2
✓ Branch 0 taken 282631 times.
✓ Branch 1 taken 54877 times.
337508 dec_arg, false, unsigned_arg) {
2785 337508 precision =
2786 337508 std::min(my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg),
2787 337508 uint(DECIMAL_MAX_PRECISION));
2788
2/4
✓ Branch 0 taken 337508 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 337508 times.
✗ Branch 3 not taken.
337508 assert((precision <= DECIMAL_MAX_PRECISION) && (dec <= DECIMAL_MAX_SCALE));
2789
1/2
✓ Branch 0 taken 337508 times.
✗ Branch 1 not taken.
337508 bin_size = my_decimal_get_binary_size(precision, dec);
2790 337508 }
2791
2792 337507 Field *Field_new_decimal::create_from_item(const Item *item) {
2793 337507 uint8 dec = item->decimals;
2794 337507 uint8 intg = item->decimal_precision() - dec;
2795 337507 uint32 len = item->max_char_length();
2796
2797
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 337507 times.
337507 assert(item->result_type() == DECIMAL_RESULT);
2798
2799 /*
2800 Trying to put too many digits overall in a DECIMAL(prec,dec)
2801 will always throw a warning. We must limit dec to
2802 DECIMAL_MAX_SCALE however to prevent an assert() later.
2803 */
2804
2805
2/2
✓ Branch 0 taken 27035 times.
✓ Branch 1 taken 310472 times.
337507 if (dec > 0) {
2806 signed int overflow;
2807
2808 27035 dec = min<int>(dec, DECIMAL_MAX_SCALE);
2809
2810 /*
2811 If the value still overflows the field with the corrected dec,
2812 we'll throw out decimals rather than integers. This is still
2813 bad and of course throws a truncation warning.
2814 +1: for decimal point
2815 */
2816
2817 const int required_length =
2818 27035 my_decimal_precision_to_length(intg + dec, dec, item->unsigned_flag);
2819
2820 27035 overflow = required_length - len;
2821
2822
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27035 times.
27035 if (overflow > 0)
2823 dec = max(0, dec - overflow); // too long, discard fract
2824 else
2825 /* Corrected value fits. */
2826 27035 len = required_length;
2827 }
2828 337507 return new (*THR_MALLOC)
2829 337507 Field_new_decimal(len, item->is_nullable(), item->item_name.ptr(), dec,
2830
2/4
✓ Branch 0 taken 337507 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 337507 times.
✗ Branch 3 not taken.
337507 item->unsigned_flag);
2831 }
2832
2833 509789 type_conversion_status Field_new_decimal::reset() {
2834 509789 (void)my_decimal2binary(0, &decimal_zero, ptr, precision, dec);
2835 509794 return TYPE_OK;
2836 }
2837
2838 /**
2839 Generate max/min decimal value in case of overflow.
2840
2841 @param decimal_value buffer for value
2842 @param sign sign of value which caused overflow
2843 */
2844
2845 601 void Field_new_decimal::set_value_on_overflow(my_decimal *decimal_value,
2846 bool sign) const {
2847
1/2
✓ Branch 0 taken 601 times.
✗ Branch 1 not taken.
601 DBUG_TRACE;
2848
1/2
✓ Branch 0 taken 601 times.
✗ Branch 1 not taken.
601 max_my_decimal(decimal_value, precision, decimals());
2849
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 505 times.
601 if (sign) {
2850
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 93 times.
96 if (is_unsigned())
2851 3 my_decimal_set_zero(decimal_value);
2852 else
2853 93 decimal_value->sign(true);
2854 }
2855 601 }
2856
2857 /**
2858 Store decimal value in the binary buffer.
2859
2860 Checks if decimal_value fits into field size.
2861 If it does, stores the decimal in the buffer using binary format.
2862 Otherwise sets maximal number that can be stored in the field.
2863
2864 @param decimal_value my_decimal
2865
2866 @retval
2867 0 ok
2868 @retval
2869 1 error
2870 */
2871 5896611 type_conversion_status Field_new_decimal::store_value(
2872 const my_decimal *decimal_value) {
2873
4/6
✓ Branch 0 taken 5896613 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5883693 times.
✓ Branch 3 taken 12920 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5883720 times.
5896611 ASSERT_COLUMN_MARKED_FOR_WRITE;
2874 5896638 type_conversion_status error = TYPE_OK;
2875
1/2
✓ Branch 0 taken 5896670 times.
✗ Branch 1 not taken.
5896638 DBUG_TRACE;
2876 #ifndef NDEBUG
2877 {
2878 char dbug_buff[DECIMAL_MAX_STR_LENGTH + 2];
2879
3/10
✓ Branch 0 taken 5896672 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5896675 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5896675 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
5896670 DBUG_PRINT("enter",
2880 ("value: %s", dbug_decimal_as_string(dbug_buff, decimal_value)));
2881 }
2882 #endif
2883
2884 /* check that we do not try to write negative value in unsigned field */
2885
6/6
✓ Branch 0 taken 5996 times.
✓ Branch 1 taken 5890663 times.
✓ Branch 2 taken 248 times.
✓ Branch 3 taken 5750 times.
✓ Branch 4 taken 248 times.
✓ Branch 5 taken 5896413 times.
5896675 if (is_unsigned() && decimal_value->sign()) {
2886
3/8
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 248 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 248 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
248 DBUG_PRINT("info", ("unsigned overflow"));
2887
1/2
✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
248 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
2888 248 error = TYPE_WARN_OUT_OF_RANGE;
2889 248 decimal_value = &decimal_zero;
2890 }
2891 #ifndef NDEBUG
2892 {
2893 char dbug_buff[DECIMAL_MAX_STR_LENGTH + 2];
2894
3/10
✓ Branch 0 taken 5896642 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5896668 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5896668 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
5896661 DBUG_PRINT("info",
2895 ("saving with precision %d scale: %d value %s", (int)precision,
2896 (int)dec, dbug_decimal_as_string(dbug_buff, decimal_value)));
2897 }
2898 #endif
2899
2900 11793313 int err = my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
2901
1/2
✓ Branch 0 taken 5896645 times.
✗ Branch 1 not taken.
5896668 decimal_value, ptr, precision, dec);
2902
3/4
✓ Branch 0 taken 5896611 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 510 times.
✓ Branch 3 taken 5896101 times.
5896645 if (warn_if_overflow(err)) {
2903 510 my_decimal buff;
2904
3/8
✓ Branch 0 taken 510 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 510 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 510 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
510 DBUG_PRINT("info", ("overflow"));
2905
1/2
✓ Branch 0 taken 510 times.
✗ Branch 1 not taken.
510 set_value_on_overflow(&buff, decimal_value->sign());
2906
1/2
✓ Branch 0 taken 510 times.
✗ Branch 1 not taken.
510 my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
2907 510 }
2908
2/6
✓ Branch 0 taken 5896633 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5896633 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5896611 DBUG_EXECUTE("info", print_decimal_buff(decimal_value, ptr, bin_size););
2909
2/2
✓ Branch 0 taken 5966 times.
✓ Branch 1 taken 5890664 times.
11793302 return (err != E_DEC_OK) ? decimal_err_to_type_conv_status(err) : error;
2910 5896630 }
2911
2912 19753 type_conversion_status Field_new_decimal::store(
2913 const char *from, size_t length, const CHARSET_INFO *charset_arg) {
2914
4/6
✓ Branch 0 taken 19753 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9270 times.
✓ Branch 3 taken 10483 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9270 times.
19753 ASSERT_COLUMN_MARKED_FOR_WRITE;
2915 19753 my_decimal decimal_value;
2916
1/2
✓ Branch 0 taken 19753 times.
✗ Branch 1 not taken.
19753 DBUG_TRACE;
2917
2918
1/2
✓ Branch 0 taken 19753 times.
✗ Branch 1 not taken.
19753 THD *thd = current_thd;
2919
2920 int err =
2921
1/2
✓ Branch 0 taken 19753 times.
✗ Branch 1 not taken.
19753 str2my_decimal(E_DEC_FATAL_ERROR & ~(E_DEC_OVERFLOW | E_DEC_BAD_NUM),
2922 from, length, charset_arg, &decimal_value);
2923
2924
8/8
✓ Branch 0 taken 196 times.
✓ Branch 1 taken 19557 times.
✓ Branch 2 taken 194 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 31 times.
✓ Branch 5 taken 163 times.
✓ Branch 6 taken 31 times.
✓ Branch 7 taken 19722 times.
19753 if (err != 0 && !thd->lex->is_ignore() && thd->is_strict_mode()) {
2925
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 ErrConvString errmsg(from, length, charset_arg);
2926 31 const Diagnostics_area *da = thd->get_stmt_da();
2927
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
31 push_warning_printf(
2928 thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
2929 ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), "decimal",
2930 errmsg.ptr(), field_name, da->current_row_for_condition());
2931
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
31 if (err == E_DEC_BAD_NUM) return store_value(&decimal_value);
2932 // Ensure that we always store something for virtual generated columns.
2933
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7 if (is_virtual_gcol()) (void)store_value(&decimal_value);
2934 7 return decimal_err_to_type_conv_status(err);
2935 }
2936
2937
2/2
✓ Branch 0 taken 165 times.
✓ Branch 1 taken 19557 times.
19722 if (err != 0) {
2938
1/2
✓ Branch 0 taken 165 times.
✗ Branch 1 not taken.
165 set_decimal_warning(thd, this, err, &decimal_value, from, length,
2939 charset_arg);
2940 }
2941 #ifndef NDEBUG
2942 char dbug_buff[DECIMAL_MAX_STR_LENGTH + 2];
2943
3/10
✓ Branch 0 taken 19722 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19722 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 19722 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
19722 DBUG_PRINT("enter",
2944 ("value: %s", dbug_decimal_as_string(dbug_buff, &decimal_value)));
2945 #endif
2946
2947
1/2
✓ Branch 0 taken 19722 times.
✗ Branch 1 not taken.
19722 type_conversion_status store_stat = store_value(&decimal_value);
2948
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 123 times.
165 return (err != 0 && err != E_DEC_BAD_NUM)
2949
2/2
✓ Branch 0 taken 165 times.
✓ Branch 1 taken 19557 times.
19887 ? decimal_err_to_type_conv_status(err)
2950 19722 : store_stat;
2951 19753 }
2952
2953 8432 type_conversion_status store_internal_with_error_check(Field_new_decimal *field,
2954 int err,
2955 my_decimal *value) {
2956 8432 THD *thd = current_thd;
2957
2958 8432 type_conversion_status stat = TYPE_OK;
2959
2/2
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 8363 times.
8432 if (err == E_DEC_OVERFLOW) {
2960 69 field->set_value_on_overflow(value, value->sign());
2961 69 stat = TYPE_WARN_OUT_OF_RANGE;
2962
2/2
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 8248 times.
8363 } else if (err == E_DEC_TRUNCATED) {
2963 115 stat = TYPE_NOTE_TRUNCATED;
2964 }
2965 8432 uint cond_count = thd->get_stmt_da()->cond_count();
2966 8432 type_conversion_status store_stat = field->store_value(value);
2967
2/2
✓ Branch 0 taken 627 times.
✓ Branch 1 taken 7805 times.
8432 if (store_stat != TYPE_OK)
2968 627 return store_stat;
2969
5/6
✓ Branch 0 taken 135 times.
✓ Branch 1 taken 7670 times.
✓ Branch 2 taken 135 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 135 times.
✓ Branch 5 taken 7670 times.
7805 else if (err != 0 && thd->get_stmt_da()->cond_count() == cond_count) {
2970 /* Only issue a warning if store_value doesn't issue an warning */
2971 135 field->warn_if_overflow(err);
2972 }
2973 7805 return stat;
2974 }
2975
2976 /**
2977 @todo
2978 Fix following when double2my_decimal when double2decimal
2979 will return E_DEC_TRUNCATED always correctly
2980 */
2981
2982 1209 type_conversion_status Field_new_decimal::store(double nr) {
2983
3/6
✓ Branch 0 taken 1209 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1209 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1209 times.
1209 ASSERT_COLUMN_MARKED_FOR_WRITE;
2984
1/2
✓ Branch 0 taken 1209 times.
✗ Branch 1 not taken.
1209 DBUG_TRACE;
2985 1209 my_decimal decimal_value;
2986
2987
1/2
✓ Branch 0 taken 1209 times.
✗ Branch 1 not taken.
1209 int conv_err = double2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr,
2988 &decimal_value);
2989
1/2
✓ Branch 0 taken 1209 times.
✗ Branch 1 not taken.
2418 return store_internal_with_error_check(this, conv_err, &decimal_value);
2990 1209 }
2991
2992 7203 type_conversion_status Field_new_decimal::store(longlong nr,
2993 bool unsigned_val) {
2994
4/6
✓ Branch 0 taken 7203 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7091 times.
✓ Branch 3 taken 112 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 7091 times.
7203 ASSERT_COLUMN_MARKED_FOR_WRITE;
2995
1/2
✓ Branch 0 taken 7203 times.
✗ Branch 1 not taken.
7203 DBUG_TRACE;
2996 7203 my_decimal decimal_value;
2997
1/2
✓ Branch 0 taken 7203 times.
✗ Branch 1 not taken.
7203 int conv_err = int2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr,
2998 unsigned_val, &decimal_value);
2999
1/2
✓ Branch 0 taken 7203 times.
✗ Branch 1 not taken.
14406 return store_internal_with_error_check(this, conv_err, &decimal_value);
3000 7203 }
3001
3002 5868432 type_conversion_status Field_new_decimal::store_decimal(
3003 const my_decimal *decimal_value) {
3004
4/6
✓ Branch 0 taken 5868445 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5866120 times.
✓ Branch 3 taken 2325 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5866132 times.
5868432 ASSERT_COLUMN_MARKED_FOR_WRITE;
3005 5868444 return store_value(decimal_value);
3006 }
3007
3008 2 type_conversion_status Field_new_decimal::store_time(MYSQL_TIME *ltime, uint8) {
3009 2 my_decimal decimal_value;
3010
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 return store_value(date2my_decimal(ltime, &decimal_value));
3011 2 }
3012
3013 4773 double Field_new_decimal::val_real() const {
3014
4/6
✓ Branch 0 taken 4773 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4772 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4772 times.
4773 ASSERT_COLUMN_MARKED_FOR_READ;
3015 double dbl;
3016 4773 my_decimal decimal_value;
3017
2/4
✓ Branch 0 taken 4773 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4773 times.
✗ Branch 3 not taken.
4773 my_decimal2double(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), &dbl);
3018 4773 return dbl;
3019 4773 }
3020
3021 489 longlong Field_new_decimal::val_int() const {
3022
3/6
✓ Branch 0 taken 489 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 489 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 489 times.
489 ASSERT_COLUMN_MARKED_FOR_READ;
3023 longlong i;
3024 489 my_decimal decimal_value;
3025
2/4
✓ Branch 0 taken 489 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 489 times.
✗ Branch 3 not taken.
489 my_decimal2int(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), is_unsigned(),
3026 &i);
3027 489 return i;
3028 489 }
3029
3030 4098736 my_decimal *Field_new_decimal::val_decimal(my_decimal *decimal_value) const {
3031
4/6
✓ Branch 0 taken 4098747 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4050342 times.
✓ Branch 3 taken 48405 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4050356 times.
4098736 ASSERT_COLUMN_MARKED_FOR_READ;
3032
1/2
✓ Branch 0 taken 4098785 times.
✗ Branch 1 not taken.
4098750 DBUG_TRACE;
3033 4098785 binary2my_decimal(E_DEC_FATAL_ERROR, ptr, decimal_value, precision, dec,
3034
1/2
✓ Branch 0 taken 4098738 times.
✗ Branch 1 not taken.
4098785 m_keep_precision);
3035
2/6
✓ Branch 0 taken 4098779 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4098779 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4098738 DBUG_EXECUTE("info", print_decimal_buff(decimal_value, ptr, bin_size););
3036 4098786 return decimal_value;
3037 4098779 }
3038
3039 71943 String *Field_new_decimal::val_str(String *val_buffer, String *) const {
3040
4/6
✓ Branch 0 taken 71943 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23736 times.
✓ Branch 3 taken 48207 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 23736 times.
71943 ASSERT_COLUMN_MARKED_FOR_READ;
3041 71943 my_decimal decimal_value;
3042
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 71831 times.
71943 uint fixed_precision = zerofill ? precision : 0;
3043
1/2
✓ Branch 0 taken 71943 times.
✗ Branch 1 not taken.
71943 my_decimal2string(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
3044
1/2
✓ Branch 0 taken 71943 times.
✗ Branch 1 not taken.
71943 fixed_precision, dec, val_buffer);
3045 71943 val_buffer->set_charset(&my_charset_numeric);
3046 71943 return val_buffer;
3047 71943 }
3048
3049 12 bool Field_new_decimal::get_date(MYSQL_TIME *ltime,
3050 my_time_flags_t fuzzydate) const {
3051
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 my_decimal buf, *decimal_value = val_decimal(&buf);
3052
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (!decimal_value) {
3053 set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME);
3054 return true;
3055 }
3056
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 return my_decimal_to_datetime_with_warn(decimal_value, ltime, fuzzydate);
3057 12 }
3058
3059 20 bool Field_new_decimal::get_time(MYSQL_TIME *ltime) const {
3060
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 my_decimal buf, *decimal_value = val_decimal(&buf);
3061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (!decimal_value) {
3062 set_zero_time(ltime, MYSQL_TIMESTAMP_TIME);
3063 return true;
3064 }
3065
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 return my_decimal_to_time_with_warn(decimal_value, ltime);
3066 20 }
3067
3068 22509 int Field_new_decimal::cmp(const uchar *a, const uchar *b) const {
3069 22509 return memcmp(a, b, bin_size);
3070 }
3071
3072 7911 size_t Field_new_decimal::make_sort_key(uchar *buff, size_t length) const {
3073 7911 memcpy(buff, ptr, min(length, static_cast<size_t>(bin_size)));
3074 7911 return length;
3075 }
3076
3077 243110 void Field_new_decimal::sql_type(String &str) const {
3078 243110 const CHARSET_INFO *cs = str.charset();
3079 243110 str.length(cs->cset->snprintf(cs, str.ptr(), str.alloced_length(),
3080 243110 "decimal(%d,%d)", precision, (int)dec));
3081 243110 append_zerofill_and_unsigned(this, &str);
3082 243110 }
3083
3084 /**
3085 Save the field metadata for new decimal fields.
3086
3087 Saves the precision in the first byte and decimals() in the second
3088 byte of the field metadata array at index of *metadata_ptr and
3089 *(metadata_ptr + 1).
3090
3091 @param metadata_ptr First byte of field metadata
3092
3093 @returns number of bytes written to metadata_ptr
3094 */
3095 27703 int Field_new_decimal::do_save_field_metadata(uchar *metadata_ptr) const {
3096 27703 *metadata_ptr = precision;
3097 27703 *(metadata_ptr + 1) = decimals();
3098 27708 return 2;
3099 }
3100
3101 /**
3102 Returns the number of bytes field uses in row-based replication
3103 row packed size.
3104
3105 This method is used in row-based replication to determine the number
3106 of bytes that the field consumes in the row record format. This is
3107 used to skip fields in the master that do not exist on the slave.
3108
3109 @param field_metadata Encoded size in field metadata
3110
3111 @returns The size of the field based on the field metadata.
3112 */
3113 uint Field_new_decimal::pack_length_from_metadata(uint field_metadata) const {
3114 uint const source_precision = (field_metadata >> 8U) & 0x00ff;
3115 uint const source_decimal = field_metadata & 0x00ff;
3116 uint const source_size =
3117 my_decimal_get_binary_size(source_precision, source_decimal);
3118 return (source_size);
3119 }
3120
3121 /**
3122 Check to see if field size is compatible with destination.
3123
3124 This method is used in row-based replication to verify that the slave's
3125 field size is less than or equal to the master's field size. The
3126 encoded field metadata (from the master or source) is decoded and compared
3127 to the size of this field (the slave or destination).
3128
3129 @param field_metadata Encoded size in field metadata
3130 @param order_var Pointer to variable where the order
3131 between the source field and this field
3132 will be returned.
3133
3134 @return @c true
3135 */
3136 1691 bool Field_new_decimal::compatible_field_size(uint field_metadata,
3137 Relay_log_info *, uint16,
3138 int *order_var) const {
3139 1691 uint const source_precision = (field_metadata >> 8U) & 0x00ff;
3140 1691 uint const source_decimal = field_metadata & 0x00ff;
3141 1691 int order = compare(source_precision, precision);
3142
2/2
✓ Branch 0 taken 1671 times.
✓ Branch 1 taken 20 times.
1691 *order_var = order != 0 ? order : compare(source_decimal, dec);
3143 1691 return true;
3144 }
3145
3146 1307 uint Field_new_decimal::is_equal(const Create_field *new_field) const {
3147
2/2
✓ Branch 0 taken 1255 times.
✓ Branch 1 taken 33 times.
2595 return (new_field->sql_type == real_type()) &&
3148 1288 (Overlaps(new_field->flags, UNSIGNED_FLAG) ==
3149
1/2
✓ Branch 0 taken 1255 times.
✗ Branch 1 not taken.
2543 is_flag_set(UNSIGNED_FLAG)) &&
3150 1255 (Overlaps(new_field->flags, AUTO_INCREMENT_FLAG) ==
3151 1255 is_flag_set(AUTO_INCREMENT_FLAG)) &&
3152
4/4
✓ Branch 0 taken 1288 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 1229 times.
✓ Branch 3 taken 26 times.
3824 (new_field->max_display_width_in_bytes() == max_display_length()) &&
3153
2/2
✓ Branch 0 taken 1221 times.
✓ Branch 1 taken 8 times.
2536 (new_field->decimals == dec);
3154 }
3155
3156 /**
3157 Unpack a decimal field from row data.
3158
3159 This method is used to unpack a decimal or numeric field from a master
3160 whose size of the field is less than that of the slave.
3161
3162 @param to Destination of the data
3163 @param from Source of the data
3164 @param param_data Precision (upper) and decimal (lower) values
3165
3166 @return New pointer into memory based on from + length of the data
3167 */
3168 133338 const uchar *Field_new_decimal::unpack(uchar *to, const uchar *from,
3169 uint param_data) {
3170
2/2
✓ Branch 0 taken 128816 times.
✓ Branch 1 taken 4522 times.
133338 if (param_data == 0) return Field::unpack(to, from, param_data);
3171
3172 4522 uint from_precision = (param_data & 0xff00) >> 8U;
3173 4522 uint from_decimal = param_data & 0x00ff;
3174 4522 uint length = pack_length();
3175 4522 uint from_pack_len = my_decimal_get_binary_size(from_precision, from_decimal);
3176
2/4
✓ Branch 0 taken 4522 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4522 times.
4522 uint len = (param_data && (from_pack_len < length)) ? from_pack_len : length;
3177
1/2
✓ Branch 0 taken 4522 times.
✗ Branch 1 not taken.
4522 if ((from_pack_len && (from_pack_len < length)) ||
3178
4/8
✓ Branch 0 taken 4522 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4522 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4522 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4522 times.
9044 (from_precision < precision) || (from_decimal < decimals())) {
3179 /*
3180 If the master's data is smaller than the slave, we need to convert
3181 the binary to decimal then resize the decimal converting it back to
3182 a decimal and write that to the raw data buffer.
3183 */
3184 decimal_digit_t dec_buf[DECIMAL_MAX_PRECISION];
3185 decimal_t dec_val;
3186 dec_val.len = from_precision;
3187 dec_val.buf = dec_buf;
3188 /*
3189 Note: bin2decimal does not change the length of the field. So it is
3190 just the first step the resizing operation. The second step does the
3191 resizing using the precision and decimals from the slave.
3192 */
3193 bin2decimal(from, &dec_val, from_precision, from_decimal);
3194 decimal2bin(&dec_val, to, precision, decimals());
3195 } else
3196 4522 memcpy(to, from, len); // Sizes are the same, just copy the data.
3197 4522 return from + len;
3198 }
3199
3200 46066 bool Field_new_decimal::send_to_protocol(Protocol *protocol) const {
3201
4/6
✓ Branch 0 taken 46066 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18300 times.
✓ Branch 3 taken 27766 times.
✓ Branch 4 taken 18300 times.
✗ Branch 5 not taken.
46066 if (is_null()) return protocol->store_null();
3202 27766 my_decimal dec_value;
3203
2/4
✓ Branch 0 taken 27766 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27766 times.
✗ Branch 3 not taken.
27766 return protocol->store_decimal(val_decimal(&dec_value),
3204
2/2
✓ Branch 0 taken 2635 times.
✓ Branch 1 taken 25131 times.
55532 zerofill ? precision : 0, dec);
3205 27766 }
3206
3207 /****************************************************************************
3208 ** tiny int
3209 ****************************************************************************/
3210
3211 460843 type_conversion_status Field_tiny::store(const char *from, size_t len,
3212 const CHARSET_INFO *cs) {
3213
4/6
✓ Branch 0 taken 460843 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 452011 times.
✓ Branch 3 taken 8832 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 452012 times.
460843 ASSERT_COLUMN_MARKED_FOR_WRITE;
3214 longlong rnd;
3215
3216 const type_conversion_status error =
3217
1/2
✓ Branch 0 taken 460847 times.
✗ Branch 1 not taken.
460844 get_int(cs, from, len, &rnd, 255, -128, 127);
3218 460847 ptr[0] = is_unsigned() ? (char)(ulonglong)rnd : (char)rnd;
3219 460847 return error;
3220 }
3221
3222 76 type_conversion_status Field_tiny::store(double nr) {
3223
4/6
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 70 times.
76 ASSERT_COLUMN_MARKED_FOR_WRITE;
3224 76 type_conversion_status error = TYPE_OK;
3225 76 nr = rint(nr);
3226
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 53 times.
76 if (is_unsigned()) {
3227
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 19 times.
23 if (nr < 0.0) {
3228 4 *ptr = 0;
3229 4 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3230 4 error = TYPE_WARN_OUT_OF_RANGE;
3231
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 15 times.
19 } else if (nr > 255.0) {
3232 4 *ptr = (char)255;
3233 4 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3234 4 error = TYPE_WARN_OUT_OF_RANGE;
3235 } else
3236 15 *ptr = static_cast<unsigned char>(nr);
3237 } else {
3238
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 31 times.
53 if (nr < -128.0) {
3239 22 *ptr = (char)-128;
3240 22 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3241 22 error = TYPE_WARN_OUT_OF_RANGE;
3242
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 3 times.
31 } else if (nr > 127.0) {
3243 28 *ptr = 127;
3244 28 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3245 28 error = TYPE_WARN_OUT_OF_RANGE;
3246 } else
3247 3 *ptr = (char)(int)nr;
3248 }
3249 76 return error;
3250 }
3251
3252 59486923 type_conversion_status Field_tiny::store(longlong nr, bool unsigned_val) {
3253
4/6
✓ Branch 0 taken 59486923 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59484123 times.
✓ Branch 3 taken 2800 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 59484123 times.
59486923 ASSERT_COLUMN_MARKED_FOR_WRITE;
3254 59486923 type_conversion_status error = TYPE_OK;
3255
3256
2/2
✓ Branch 0 taken 137880 times.
✓ Branch 1 taken 59349043 times.
59486923 if (is_unsigned()) {
3257
4/4
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 137775 times.
✓ Branch 2 taken 94 times.
✓ Branch 3 taken 11 times.
137880 if (nr < 0 && !unsigned_val) {
3258 94 *ptr = 0;
3259 94 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3260 94 error = TYPE_WARN_OUT_OF_RANGE;
3261
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 137730 times.
137786 } else if ((ulonglong)nr > (ulonglong)255) {
3262 56 *ptr = (char)255;
3263 56 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3264 56 error = TYPE_WARN_OUT_OF_RANGE;
3265 } else
3266 137730 *ptr = (char)nr;
3267 } else {
3268
4/4
✓ Branch 0 taken 4981 times.
✓ Branch 1 taken 59344062 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 4975 times.
59349043 if (nr < 0 && unsigned_val) nr = 256; // Generate overflow
3269
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 59348975 times.
59349043 if (nr < -128) {
3270 68 *ptr = (char)-128;
3271 68 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3272 68 error = TYPE_WARN_OUT_OF_RANGE;
3273
2/2
✓ Branch 0 taken 222 times.
✓ Branch 1 taken 59348753 times.
59348975 } else if (nr > 127) {
3274 222 *ptr = 127;
3275 222 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3276 222 error = TYPE_WARN_OUT_OF_RANGE;
3277 } else
3278 59348753 *ptr = (char)nr;
3279 }
3280 59486923 return error;
3281 }
3282
3283 3458 double Field_tiny::val_real() const {
3284
3/6
✓ Branch 0 taken 3458 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3458 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3458 times.
3458 ASSERT_COLUMN_MARKED_FOR_READ;
3285
2/2
✓ Branch 0 taken 1710 times.
✓ Branch 1 taken 1748 times.
3458 int tmp = is_unsigned() ? (int)ptr[0] : (int)((signed char *)ptr)[0];
3286 3458 return (double)tmp;
3287 }
3288
3289 264895001 longlong Field_tiny::val_int() const {
3290
4/6
✓ Branch 0 taken 264895002 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 264893547 times.
✓ Branch 3 taken 1455 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 264893547 times.
264895001 ASSERT_COLUMN_MARKED_FOR_READ;
3291
2/2
✓ Branch 0 taken 703593 times.
✓ Branch 1 taken 264191410 times.
264895001 int tmp = is_unsigned() ? (int)ptr[0] : (int)((signed char *)ptr)[0];
3292 264895003 return (longlong)tmp;
3293 }
3294
3295 78328 String *Field_tiny::val_str(String *val_buffer, String *) const {
3296
4/6
✓ Branch 0 taken 78328 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68207 times.
✓ Branch 3 taken 10121 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 68207 times.
78328 ASSERT_COLUMN_MARKED_FOR_READ;
3297 78328 const CHARSET_INFO *cs = &my_charset_numeric;
3298 uint length;
3299 78328 uint mlength = max(field_length + 1, 5 * cs->mbmaxlen);
3300 78328 val_buffer->alloc(mlength);
3301 78328 char *to = val_buffer->ptr();
3302
3303
2/2
✓ Branch 0 taken 6785 times.
✓ Branch 1 taken 71543 times.
78328 if (is_unsigned())
3304 6785 length = (uint)cs->cset->long10_to_str(cs, to, mlength, 10, (long)*ptr);
3305 else
3306 71543 length = (uint)cs->cset->long10_to_str(cs, to, mlength, -10,
3307 71543 (long)*((signed char *)ptr));
3308
3309 78328 val_buffer->length(length);
3310
2/2
✓ Branch 0 taken 1351 times.
✓ Branch 1 taken 76977 times.
78328 if (zerofill) prepend_zeros(val_buffer);
3311 78328 val_buffer->set_charset(cs);
3312 78328 return val_buffer;
3313 }
3314
3315 79432 bool Field_tiny::send_to_protocol(Protocol *protocol) const {
3316
2/2
✓ Branch 0 taken 3783 times.
✓ Branch 1 taken 75649 times.
79432 if (is_null()) return protocol->store_null();
3317 75649 return protocol->store_tiny(Field_tiny::val_int(),
3318
2/2
✓ Branch 0 taken 16595 times.
✓ Branch 1 taken 59054 times.
151298 zerofill ? field_length : 0);
3319 }
3320
3321 4108 int Field_tiny::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
3322 signed char a, b;
3323 4108 a = (signed char)a_ptr[0];
3324 4108 b = (signed char)b_ptr[0];
3325
2/2
✓ Branch 0 taken 2778 times.
✓ Branch 1 taken 1330 times.
4108 if (is_unsigned())
3326
4/4
✓ Branch 0 taken 1358 times.
✓ Branch 1 taken 1420 times.
✓ Branch 2 taken 442 times.
✓ Branch 3 taken 916 times.
2778 return ((uchar)a < (uchar)b) ? -1 : ((uchar)a > (uchar)b) ? 1 : 0;
3327
4/4
✓ Branch 0 taken 889 times.
✓ Branch 1 taken 441 times.
✓ Branch 2 taken 243 times.
✓ Branch 3 taken 646 times.
1330 return (a < b) ? -1 : (a > b) ? 1 : 0;
3328 }
3329
3330 6617 size_t Field_tiny::make_sort_key(uchar *to,
3331 size_t length [[maybe_unused]]) const {
3332
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6617 times.
6617 assert(length == 1);
3333
2/2
✓ Branch 0 taken 2251 times.
✓ Branch 1 taken 4366 times.
6617 if (is_unsigned())
3334 2251 *to = *ptr;
3335 else
3336 4366 to[0] = (char)(ptr[0] ^ (uchar)128); /* Revers signbit */
3337 6617 return 1;
3338 }
3339
3340 284081 void Field_tiny::sql_type(String &res) const {
3341
7/8
✓ Branch 0 taken 245360 times.
✓ Branch 1 taken 38721 times.
✓ Branch 2 taken 244937 times.
✓ Branch 3 taken 423 times.
✓ Branch 4 taken 244937 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 244937 times.
✓ Branch 7 taken 39144 times.
284081 if (field_length == 1 && !is_unsigned() && !zerofill) {
3342 // Print TINYINT(1) since connectors use this to indicate BOOLEAN
3343 244937 res.length(0);
3344
1/2
✓ Branch 0 taken 244937 times.
✗ Branch 1 not taken.
244937 res.append("tinyint(1)");
3345 } else {
3346 39144 integer_sql_type(this, "tinyint", &res);
3347 }
3348 284081 }
3349
3350 /****************************************************************************
3351 Field type short int (2 byte)
3352 ****************************************************************************/
3353
3354 1428 type_conversion_status Field_short::store(const char *from, size_t len,
3355 const CHARSET_INFO *cs) {
3356
4/6
✓ Branch 0 taken 1428 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 968 times.
✓ Branch 3 taken 460 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 968 times.
1428 ASSERT_COLUMN_MARKED_FOR_WRITE;
3357 int store_tmp;
3358 longlong rnd;
3359
3360 const type_conversion_status error =
3361
1/2
✓ Branch 0 taken 1428 times.
✗ Branch 1 not taken.
1428 get_int(cs, from, len, &rnd, UINT_MAX16, INT_MIN16, INT_MAX16);
3362 1428 store_tmp = is_unsigned() ? (int)(ulonglong)rnd : (int)rnd;
3363
1/2
✓ Branch 0 taken 1428 times.
✗ Branch 1 not taken.
1428 if (table->s->db_low_byte_first)
3364 1428 int2store(ptr, store_tmp);
3365 else
3366 shortstore(ptr, (short)store_tmp);
3367 1428 return error;
3368 }
3369
3370 91 type_conversion_status Field_short::store(double nr) {
3371
3/6
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 91 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 91 times.
91 ASSERT_COLUMN_MARKED_FOR_WRITE;
3372 91 type_conversion_status error = TYPE_OK;
3373 int16 res;
3374 91 nr = rint(nr);
3375
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 36 times.
91 if (is_unsigned()) {
3376
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 49 times.
55 if (nr < 0) {
3377 6 res = 0;
3378 6 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3379 6 error = TYPE_WARN_OUT_OF_RANGE;
3380
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
49 } else if (nr > UINT_MAX16) {
3381 res = (int16)UINT_MAX16;
3382 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3383 error = TYPE_WARN_OUT_OF_RANGE;
3384 } else
3385 49 res = (int16)(uint16)nr;
3386 } else {
3387
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
36 if (nr < INT_MIN16) {
3388 18 res = INT_MIN16;
3389 18 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3390 18 error = TYPE_WARN_OUT_OF_RANGE;
3391
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 } else if (nr > INT_MAX16) {
3392 18 res = INT_MAX16;
3393 18 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3394 18 error = TYPE_WARN_OUT_OF_RANGE;
3395 } else
3396 res = (int16)(int)nr;
3397 }
3398
1/2
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
91 if (table->s->db_low_byte_first)
3399 91 int2store(ptr, res);
3400 else
3401 shortstore(ptr, res);
3402 91 return error;
3403 }
3404
3405 587224 type_conversion_status Field_short::store(longlong nr, bool unsigned_val) {
3406
4/6
✓ Branch 0 taken 587224 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 587063 times.
✓ Branch 3 taken 161 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 587063 times.
587224 ASSERT_COLUMN_MARKED_FOR_WRITE;
3407 587224 type_conversion_status error = TYPE_OK;
3408 int16 res;
3409
3410
2/2
✓ Branch 0 taken 562204 times.
✓ Branch 1 taken 25020 times.
587224 if (is_unsigned()) {
3411
4/4
✓ Branch 0 taken 95 times.
✓ Branch 1 taken 562109 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 11 times.
562204 if (nr < 0L && !unsigned_val) {
3412 84 res = 0;
3413 84 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3414 84 error = TYPE_WARN_OUT_OF_RANGE;
3415
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 562079 times.
562120 } else if ((ulonglong)nr > (ulonglong)UINT_MAX16) {
3416 41 res = (int16)UINT_MAX16;
3417 41 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3418 41 error = TYPE_WARN_OUT_OF_RANGE;
3419 } else
3420 562079 res = (int16)(uint16)nr;
3421 } else {
3422
4/4
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 24430 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 584 times.
25020 if (nr < 0 && unsigned_val) nr = UINT_MAX16 + 1; // Generate overflow
3423
3424
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 24956 times.
25020 if (nr < INT_MIN16) {
3425 64 res = INT_MIN16;
3426 64 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3427 64 error = TYPE_WARN_OUT_OF_RANGE;
3428
2/2
✓ Branch 0 taken 95 times.
✓ Branch 1 taken 24861 times.
24956 } else if (nr > (longlong)INT_MAX16) {
3429 95 res = INT_MAX16;
3430 95 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3431 95 error = TYPE_WARN_OUT_OF_RANGE;
3432 } else
3433 24861 res = (int16)nr;
3434 }
3435
2/2
✓ Branch 0 taken 587214 times.
✓ Branch 1 taken 10 times.
587224 if (table->s->db_low_byte_first)
3436 587214 int2store(ptr, res);
3437 else
3438 10 shortstore(ptr, res);
3439 587224 return error;
3440 }
3441
3442 3952 double Field_short::val_real() const {
3443
3/6
✓ Branch 0 taken 3952 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3952 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3952 times.
3952 ASSERT_COLUMN_MARKED_FOR_READ;
3444 short j;
3445
1/2
✓ Branch 0 taken 3952 times.
✗ Branch 1 not taken.
3952 if (table->s->db_low_byte_first)
3446 3952 j = sint2korr(ptr);
3447 else
3448 j = shortget(ptr);
3449
2/2
✓ Branch 0 taken 1734 times.
✓ Branch 1 taken 2218 times.
3952 return is_unsigned() ? (double)(unsigned short)j : (double)j;
3450 }
3451
3452 318408 longlong Field_short::val_int() const {
3453
4/6
✓ Branch 0 taken 318408 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 318398 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 318398 times.
318408 ASSERT_COLUMN_MARKED_FOR_READ;
3454 short j;
3455
2/2
✓ Branch 0 taken 318398 times.
✓ Branch 1 taken 10 times.
318408 if (table->s->db_low_byte_first)
3456 318398 j = sint2korr(ptr);
3457 else
3458 10 j = shortget(ptr);
3459
2/2
✓ Branch 0 taken 241279 times.
✓ Branch 1 taken 77129 times.
318408 return is_unsigned() ? (longlong)(unsigned short)j : (longlong)j;
3460 }
3461
3462 7857 String *Field_short::val_str(String *val_buffer, String *) const {
3463
4/6
✓ Branch 0 taken 7857 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7353 times.
✓ Branch 3 taken 504 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 7353 times.
7857 ASSERT_COLUMN_MARKED_FOR_READ;
3464 7857 const CHARSET_INFO *cs = &my_charset_numeric;
3465 uint length;
3466 7857 uint mlength = max(field_length + 1, 7 * cs->mbmaxlen);
3467 7857 val_buffer->alloc(mlength);
3468 7857 char *to = val_buffer->ptr();
3469 short j;
3470
1/2
✓ Branch 0 taken 7857 times.
✗ Branch 1 not taken.
7857 if (table->s->db_low_byte_first)
3471 7857 j = sint2korr(ptr);
3472 else
3473 j = shortget(ptr);
3474
3475
2/2
✓ Branch 0 taken 3940 times.
✓ Branch 1 taken 3917 times.
7857 if (is_unsigned())
3476 3940 length =
3477 3940 (uint)cs->cset->long10_to_str(cs, to, mlength, 10, (long)(uint16)j);
3478 else
3479 3917 length = (uint)cs->cset->long10_to_str(cs, to, mlength, -10, (long)j);
3480 7857 val_buffer->length(length);
3481
2/2
✓ Branch 0 taken 161 times.
✓ Branch 1 taken 7696 times.
7857 if (zerofill) prepend_zeros(val_buffer);
3482 7857 val_buffer->set_charset(cs);
3483 7857 return val_buffer;
3484 }
3485
3486 77273 bool Field_short::send_to_protocol(Protocol *protocol) const {
3487
2/2
✓ Branch 0 taken 5170 times.
✓ Branch 1 taken 72103 times.
77273 if (is_null()) return protocol->store_null();
3488 72103 return protocol->store_short(Field_short::val_int(),
3489
2/2
✓ Branch 0 taken 9371 times.
✓ Branch 1 taken 62732 times.
144206 zerofill ? field_length : 0);
3490 }
3491
3492 2564 int Field_short::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
3493 short a, b;
3494
2/2
✓ Branch 0 taken 2556 times.
✓ Branch 1 taken 8 times.
2564 if (table->s->db_low_byte_first) {
3495 2556 a = sint2korr(a_ptr);
3496 2556 b = sint2korr(b_ptr);
3497 } else {
3498 8 a = shortget(a_ptr);
3499 8 b = shortget(b_ptr);
3500 }
3501
3502
2/2
✓ Branch 0 taken 1179 times.
✓ Branch 1 taken 1385 times.
2564 if (is_unsigned())
3503 1179 return ((unsigned short)a < (unsigned short)b)
3504
2/2
✓ Branch 0 taken 479 times.
✓ Branch 1 taken 700 times.
1658 ? -1
3505
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 346 times.
1658 : ((unsigned short)a > (unsigned short)b) ? 1 : 0;
3506
4/4
✓ Branch 0 taken 930 times.
✓ Branch 1 taken 455 times.
✓ Branch 2 taken 261 times.
✓ Branch 3 taken 669 times.
1385 return (a < b) ? -1 : (a > b) ? 1 : 0;
3507 }
3508
3509 8908 size_t Field_short::make_sort_key(uchar *to,
3510 size_t length [[maybe_unused]]) const {
3511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8908 times.
8908 assert(length == 2);
3512 #ifdef WORDS_BIGENDIAN
3513 if (!table->s->db_low_byte_first) {
3514 if (is_unsigned())
3515 to[0] = ptr[0];
3516 else
3517 to[0] = (char)(ptr[0] ^ 128); /* Revers signbit */
3518 to[1] = ptr[1];
3519 } else
3520 #endif
3521 {
3522
2/2
✓ Branch 0 taken 4328 times.
✓ Branch 1 taken 4580 times.
8908 if (is_unsigned())
3523 4328 to[0] = ptr[1];
3524 else
3525 4580 to[0] = (char)(ptr[1] ^ 128); /* Revers signbit */
3526 8908 to[1] = ptr[0];
3527 }
3528 8908 return 2;
3529 }
3530
3531 81229 void Field_short::sql_type(String &res) const {
3532 81229 integer_sql_type(this, "smallint", &res);
3533 81229 }
3534
3535 /****************************************************************************
3536 Field type medium int (3 byte)
3537 ****************************************************************************/
3538
3539 1239 type_conversion_status Field_medium::store(const char *from, size_t len,
3540 const CHARSET_INFO *cs) {
3541
4/6
✓ Branch 0 taken 1239 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1042 times.
✓ Branch 3 taken 197 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1042 times.
1239 ASSERT_COLUMN_MARKED_FOR_WRITE;
3542 int store_tmp;
3543 longlong rnd;
3544
3545 const type_conversion_status error =
3546
1/2
✓ Branch 0 taken 1239 times.
✗ Branch 1 not taken.
1239 get_int(cs, from, len, &rnd, UINT_MAX24, INT_MIN24, INT_MAX24);
3547 1239 store_tmp = is_unsigned() ? (int)(ulonglong)rnd : (int)rnd;
3548 1239 int3store(ptr, store_tmp);
3549 1239 return error;
3550 }
3551
3552 36 type_conversion_status Field_medium::store(double nr) {
3553
3/6
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 36 times.
36 ASSERT_COLUMN_MARKED_FOR_WRITE;
3554 36 type_conversion_status error = TYPE_OK;
3555 36 nr = rint(nr);
3556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (is_unsigned()) {
3557 if (nr < 0) {
3558 int3store(ptr, 0);
3559 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3560 error = TYPE_WARN_OUT_OF_RANGE;
3561 } else if (nr >= (double)(long)(1L << 24)) {
3562 uint32 tmp = (uint32)(1L << 24) - 1L;
3563 int3store(ptr, tmp);
3564 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3565 error = TYPE_WARN_OUT_OF_RANGE;
3566 } else
3567 int3store(ptr, (uint32)nr);
3568 } else {
3569
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
36 if (nr < INT_MIN24) {
3570 18 long tmp = (long)INT_MIN24;
3571 18 int3store(ptr, tmp);
3572 18 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3573 18 error = TYPE_WARN_OUT_OF_RANGE;
3574
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 } else if (nr > INT_MAX24) {
3575 18 long tmp = (long)INT_MAX24;
3576 18 int3store(ptr, tmp);
3577 18 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3578 18 error = TYPE_WARN_OUT_OF_RANGE;
3579 } else
3580 int3store(ptr, (long)nr);
3581 }
3582 36 return error;
3583 }
3584
3585 372269 type_conversion_status Field_medium::store(longlong nr, bool unsigned_val) {
3586
4/6
✓ Branch 0 taken 372269 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 372174 times.
✓ Branch 3 taken 95 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 372174 times.
372269 ASSERT_COLUMN_MARKED_FOR_WRITE;
3587 372269 type_conversion_status error = TYPE_OK;
3588
3589
2/2
✓ Branch 0 taken 134933 times.
✓ Branch 1 taken 237336 times.
372269 if (is_unsigned()) {
3590
4/4
✓ Branch 0 taken 59 times.
✓ Branch 1 taken 134874 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 11 times.
134933 if (nr < 0 && !unsigned_val) {
3591 48 int3store(ptr, 0);
3592 48 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3593 48 error = TYPE_WARN_OUT_OF_RANGE;
3594
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 134851 times.
134885 } else if ((ulonglong)nr >= (ulonglong)(long)(1L << 24)) {
3595 34 long tmp = (long)(1L << 24) - 1L;
3596 34 int3store(ptr, tmp);
3597 34 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3598 34 error = TYPE_WARN_OUT_OF_RANGE;
3599 } else
3600 134851 int3store(ptr, (uint32)nr);
3601 } else {
3602
4/4
✓ Branch 0 taken 10133 times.
✓ Branch 1 taken 227203 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 10127 times.
237336 if (nr < 0 && unsigned_val)
3603 6 nr = (ulonglong)(long)(1L << 24); // Generate overflow
3604
3605
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 237274 times.
237336 if (nr < (longlong)INT_MIN24) {
3606 62 long tmp = (long)INT_MIN24;
3607 62 int3store(ptr, tmp);
3608 62 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3609 62 error = TYPE_WARN_OUT_OF_RANGE;
3610
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 237102 times.
237274 } else if (nr > (longlong)INT_MAX24) {
3611 172 long tmp = (long)INT_MAX24;
3612 172 int3store(ptr, tmp);
3613 172 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3614 172 error = TYPE_WARN_OUT_OF_RANGE;
3615 } else
3616 237102 int3store(ptr, (long)nr);
3617 }
3618 372269 return error;
3619 }
3620
3621 3456 double Field_medium::val_real() const {
3622
3/6
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3456 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3456 times.
3456 ASSERT_COLUMN_MARKED_FOR_READ;
3623
2/2
✓ Branch 0 taken 1710 times.
✓ Branch 1 taken 1746 times.
3456 long j = is_unsigned() ? (long)uint3korr(ptr) : sint3korr(ptr);
3624 3456 return (double)j;
3625 }
3626
3627 974116 longlong Field_medium::val_int() const {
3628
4/6
✓ Branch 0 taken 974116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 974112 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 974112 times.
974116 ASSERT_COLUMN_MARKED_FOR_READ;
3629
2/2
✓ Branch 0 taken 279989 times.
✓ Branch 1 taken 694127 times.
974116 long j = is_unsigned() ? (long)uint3korr(ptr) : sint3korr(ptr);
3630 974116 return (longlong)j;
3631 }
3632
3633 2329 String *Field_medium::val_str(String *val_buffer, String *) const {
3634
4/6
✓ Branch 0 taken 2329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2067 times.
✓ Branch 3 taken 262 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2067 times.
2329 ASSERT_COLUMN_MARKED_FOR_READ;
3635 2329 const CHARSET_INFO *cs = &my_charset_numeric;
3636 uint length;
3637 2329 uint mlength = max(field_length + 1, 10 * cs->mbmaxlen);
3638 2329 val_buffer->alloc(mlength);
3639 2329 char *to = val_buffer->ptr();
3640
2/2
✓ Branch 0 taken 293 times.
✓ Branch 1 taken 2036 times.
2329 long j = is_unsigned() ? (long)uint3korr(ptr) : sint3korr(ptr);
3641
3642 2329 length = (uint)cs->cset->long10_to_str(cs, to, mlength, -10, j);
3643 2329 val_buffer->length(length);
3644
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 2225 times.
2329 if (zerofill) prepend_zeros(val_buffer); /* purecov: inspected */
3645 2329 val_buffer->set_charset(cs);
3646 2329 return val_buffer;
3647 }
3648
3649 40775 bool Field_medium::send_to_protocol(Protocol *protocol) const {
3650
3/6
✓ Branch 0 taken 40775 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40775 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 40775 times.
40775 ASSERT_COLUMN_MARKED_FOR_READ;
3651
2/2
✓ Branch 0 taken 2825 times.
✓ Branch 1 taken 37950 times.
40775 if (is_null()) return protocol->store_null();
3652 37950 return protocol->store_long(Field_medium::val_int(),
3653
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 37894 times.
75900 zerofill ? field_length : 0);
3654 }
3655
3656 42668 int Field_medium::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
3657 long a, b;
3658
2/2
✓ Branch 0 taken 1124 times.
✓ Branch 1 taken 41544 times.
42668 if (is_unsigned()) {
3659 1124 a = uint3korr(a_ptr);
3660 1124 b = uint3korr(b_ptr);
3661 } else {
3662 41544 a = sint3korr(a_ptr);
3663 41544 b = sint3korr(b_ptr);
3664 }
3665
4/4
✓ Branch 0 taken 31453 times.
✓ Branch 1 taken 11215 times.
✓ Branch 2 taken 8083 times.
✓ Branch 3 taken 23370 times.
42668 return (a < b) ? -1 : (a > b) ? 1 : 0;
3666 }
3667
3668 332090 size_t Field_medium::make_sort_key(uchar *to,
3669 size_t length [[maybe_unused]]) const {
3670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 332090 times.
332090 assert(length == 3);
3671
2/2
✓ Branch 0 taken 132881 times.
✓ Branch 1 taken 199209 times.
332090 if (is_unsigned())
3672 132881 to[0] = ptr[2];
3673 else
3674 199209 to[0] = (uchar)(ptr[2] ^ 128); /* Revers signbit */
3675 332090 to[1] = ptr[1];
3676 332090 to[2] = ptr[0];
3677 332090 return 3;
3678 }
3679
3680 43654 void Field_medium::sql_type(String &res) const {
3681 43654 integer_sql_type(this, "mediumint", &res);
3682 43654 }
3683
3684 /****************************************************************************
3685 ** long int
3686 ****************************************************************************/
3687
3688 3338982 type_conversion_status Field_long::store(const char *from, size_t len,
3689 const CHARSET_INFO *cs) {
3690
4/6
✓ Branch 0 taken 3338995 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3307382 times.
✓ Branch 3 taken 31613 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3307447 times.
3338982 ASSERT_COLUMN_MARKED_FOR_WRITE;
3691 long store_tmp;
3692 longlong rnd;
3693
3694 const type_conversion_status error =
3695
1/2
✓ Branch 0 taken 3339033 times.
✗ Branch 1 not taken.
3339047 get_int(cs, from, len, &rnd, UINT_MAX32, INT_MIN32, INT_MAX32);
3696 3339033 store_tmp = is_unsigned() ? (long)(ulonglong)rnd : (long)rnd;
3697
2/2
✓ Branch 0 taken 3339217 times.
✓ Branch 1 taken 10 times.
3339227 if (table->s->db_low_byte_first)
3698 3339217 int4store(ptr, store_tmp);
3699 else
3700 10 longstore(ptr, store_tmp);
3701 3339163 return error;
3702 }
3703
3704 5890703 type_conversion_status Field_long::store(double nr) {
3705
5/6
✓ Branch 0 taken 5890702 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5889180 times.
✓ Branch 3 taken 1522 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5889180 times.
5890703 ASSERT_COLUMN_MARKED_FOR_WRITE;
3706 5890703 type_conversion_status error = TYPE_OK;
3707 int32 res;
3708 5890703 nr = rint(nr);
3709
2/2
✓ Branch 0 taken 116 times.
✓ Branch 1 taken 5890588 times.
5890703 if (is_unsigned()) {
3710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 116 times.
116 if (nr < 0) {
3711 res = 0;
3712 error = TYPE_WARN_OUT_OF_RANGE;
3713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 116 times.
116 } else if (nr > UINT_MAX32) {
3714 res = UINT_MAX32;
3715 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3716 error = TYPE_WARN_OUT_OF_RANGE;
3717 } else
3718 116 res = (int32)(ulong)nr;
3719 } else {
3720
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 5890548 times.
5890588 if (nr < INT_MIN32) {
3721 40 res = (int32)INT_MIN32;
3722 40 error = TYPE_WARN_OUT_OF_RANGE;
3723
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 5890512 times.
5890548 } else if (nr > INT_MAX32) {
3724 36 res = (int32)INT_MAX32;
3725 36 error = TYPE_WARN_OUT_OF_RANGE;
3726 } else
3727 5890512 res = (int32)(longlong)nr;
3728 }
3729
2/2
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 5890628 times.
5890704 if (error)
3730 76 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3731
3732
2/2
✓ Branch 0 taken 5889179 times.
✓ Branch 1 taken 1523 times.
5890702 if (table->s->db_low_byte_first)
3733 5889179 int4store(ptr, res);
3734 else
3735 1523 longstore(ptr, res);
3736 5890702 return error;
3737 }
3738
3739 /**
3740 Store a longlong in the field
3741
3742 @param nr the value to store
3743 @param unsigned_val whether or not 'nr' should be interpreted as
3744 signed or unsigned. E.g., if 'nr' has all bits
3745 set it is interpreted as -1 if unsigned_val is
3746 false and ULLONG_MAX if unsigned_val is true.
3747 */
3748 121699083 type_conversion_status Field_long::store(longlong nr, bool unsigned_val) {
3749
4/6
✓ Branch 0 taken 121699216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121472563 times.
✓ Branch 3 taken 226653 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 121472492 times.
121699083 ASSERT_COLUMN_MARKED_FOR_WRITE;
3750 121699012 type_conversion_status error = TYPE_OK;
3751 int32 res;
3752
3753
2/2
✓ Branch 0 taken 47386518 times.
✓ Branch 1 taken 74313440 times.
121699012 if (is_unsigned()) {
3754
4/4
✓ Branch 0 taken 90111 times.
✓ Branch 1 taken 47296407 times.
✓ Branch 2 taken 90095 times.
✓ Branch 3 taken 16 times.
47386518 if (nr < 0 && !unsigned_val) {
3755 90095 res = 0;
3756 90095 error = TYPE_WARN_OUT_OF_RANGE;
3757
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 47296369 times.
47296423 } else if ((ulonglong)nr >= (1LL << 32)) {
3758 54 res = (int32)(uint32)~0L;
3759 54 error = TYPE_WARN_OUT_OF_RANGE;
3760 } else
3761 47296369 res = (int32)(uint32)nr;
3762 } else {
3763
4/4
✓ Branch 0 taken 125758 times.
✓ Branch 1 taken 74187682 times.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 125739 times.
74313440 if (nr < 0 && unsigned_val) {
3764 19 nr = ((longlong)INT_MAX32) + 1; // Generate overflow
3765 19 error = TYPE_WARN_OUT_OF_RANGE;
3766 }
3767
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 74313332 times.
74313440 if (nr < (longlong)INT_MIN32) {
3768 108 res = (int32)INT_MIN32;
3769 108 error = TYPE_WARN_OUT_OF_RANGE;
3770
2/2
✓ Branch 0 taken 277 times.
✓ Branch 1 taken 74313055 times.
74313332 } else if (nr > (longlong)INT_MAX32) {
3771 277 res = (int32)INT_MAX32;
3772 277 error = TYPE_WARN_OUT_OF_RANGE;
3773 } else
3774 74313055 res = (int32)nr;
3775 }
3776
2/2
✓ Branch 0 taken 90534 times.
✓ Branch 1 taken 121609424 times.
121699958 if (error)
3777 90534 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3778
3779
2/2
✓ Branch 0 taken 121488839 times.
✓ Branch 1 taken 210351 times.
121699190 if (table->s->db_low_byte_first)
3780 121488839 int4store(ptr, res);
3781 else
3782 210351 longstore(ptr, res);
3783 121700102 return error;
3784 }
3785
3786 2452301 double Field_long::val_real() const {
3787
4/6
✓ Branch 0 taken 2452301 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2452290 times.
✓ Branch 3 taken 11 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2452291 times.
2452301 ASSERT_COLUMN_MARKED_FOR_READ;
3788 int32 j;
3789
2/2
✓ Branch 0 taken 2452291 times.
✓ Branch 1 taken 11 times.
2452302 if (table->s->db_low_byte_first)
3790 2452291 j = sint4korr(ptr);
3791 else
3792 11 j = longget(ptr);
3793
2/2
✓ Branch 0 taken 42475 times.
✓ Branch 1 taken 2409827 times.
2452302 return is_unsigned() ? (double)(uint32)j : (double)j;
3794 }
3795
3796 433540091 longlong Field_long::val_int() const {
3797
4/6
✓ Branch 0 taken 433540268 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 433330676 times.
✓ Branch 3 taken 209592 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 433331854 times.
433540091 ASSERT_COLUMN_MARKED_FOR_READ;
3798 int32 j;
3799
2/2
✓ Branch 0 taken 433331017 times.
✓ Branch 1 taken 210252 times.
433541269 if (table->s->db_low_byte_first)
3800 433331017 j = sint4korr(ptr);
3801 else
3802 210252 j = longget(ptr);
3803
2/2
✓ Branch 0 taken 232790849 times.
✓ Branch 1 taken 200750403 times.
433541346 return is_unsigned() ? (longlong)(uint32)j : (longlong)j;
3804 }
3805
3806 2995809 String *Field_long::val_str(String *val_buffer, String *) const {
3807
4/6
✓ Branch 0 taken 2995812 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2942377 times.
✓ Branch 3 taken 53435 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2942386 times.
2995809 ASSERT_COLUMN_MARKED_FOR_READ;
3808 2995818 const CHARSET_INFO *cs = &my_charset_numeric;
3809 size_t length;
3810 2995818 uint mlength = max(field_length + 1, 12 * cs->mbmaxlen);
3811 2995823 val_buffer->alloc(mlength);
3812 2995833 char *to = val_buffer->ptr();
3813 int32 j;
3814
2/2
✓ Branch 0 taken 2994196 times.
✓ Branch 1 taken 1637 times.
2995833 if (table->s->db_low_byte_first)
3815 2994196 j = sint4korr(ptr);
3816 else
3817 1637 j = longget(ptr);
3818
3819
2/2
✓ Branch 0 taken 751934 times.
✓ Branch 1 taken 2243899 times.
2995832 if (is_unsigned())
3820 751934 length = cs->cset->long10_to_str(cs, to, mlength, 10, (long)(uint32)j);
3821 else
3822 2243899 length = cs->cset->long10_to_str(cs, to, mlength, -10, (long)j);
3823 2995829 val_buffer->length(length);
3824
2/2
✓ Branch 0 taken 75707 times.
✓ Branch 1 taken 2920120 times.
2995827 if (zerofill) prepend_zeros(val_buffer);
3825 2995827 val_buffer->set_charset(cs);
3826 2995832 return val_buffer;
3827 }
3828
3829 37733899 bool Field_long::send_to_protocol(Protocol *protocol) const {
3830
3/6
✓ Branch 0 taken 37734223 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37734446 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 37734478 times.
37733899 ASSERT_COLUMN_MARKED_FOR_READ;
3831
2/2
✓ Branch 0 taken 1617623 times.
✓ Branch 1 taken 36116782 times.
37733931 if (is_null()) return protocol->store_null();
3832 36116782 return protocol->store_long(Field_long::val_int(),
3833
2/2
✓ Branch 0 taken 15674 times.
✓ Branch 1 taken 36101108 times.
72233699 zerofill ? field_length : 0);
3834 }
3835
3836 4142608 int Field_long::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
3837 int32 a, b;
3838
1/2
✓ Branch 0 taken 4142632 times.
✗ Branch 1 not taken.
4142608 if (table->s->db_low_byte_first) {
3839 4142632 a = sint4korr(a_ptr);
3840 4142633 b = sint4korr(b_ptr);
3841 } else {
3842 a = longget(a_ptr);
3843 b = longget(b_ptr);
3844 }
3845
2/2
✓ Branch 0 taken 447944 times.
✓ Branch 1 taken 3694738 times.
4142670 if (is_unsigned())
3846
4/4
✓ Branch 0 taken 191090 times.
✓ Branch 1 taken 256854 times.
✓ Branch 2 taken 69202 times.
✓ Branch 3 taken 121888 times.
447944 return ((uint32)a < (uint32)b) ? -1 : ((uint32)a > (uint32)b) ? 1 : 0;
3847
4/4
✓ Branch 0 taken 2223326 times.
✓ Branch 1 taken 1471412 times.
✓ Branch 2 taken 731308 times.
✓ Branch 3 taken 1492018 times.
3694738 return (a < b) ? -1 : (a > b) ? 1 : 0;
3848 }
3849
3850 16286867 size_t Field_long::make_sort_key(uchar *to,
3851 size_t length [[maybe_unused]]) const {
3852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16286867 times.
16286867 assert(length == 4);
3853 #ifdef WORDS_BIGENDIAN
3854 if (!table->s->db_low_byte_first) {
3855 if (is_unsigned())
3856 to[0] = ptr[0];
3857 else
3858 to[0] = (char)(ptr[0] ^ 128); /* Reverse sign bit */
3859 to[1] = ptr[1];
3860 to[2] = ptr[2];
3861 to[3] = ptr[3];
3862 } else
3863 #endif
3864 {
3865
2/2
✓ Branch 0 taken 1062229 times.
✓ Branch 1 taken 15224645 times.
16286867 if (is_unsigned())
3866 1062229 to[0] = ptr[3];
3867 else
3868 15224645 to[0] = (char)(ptr[3] ^ 128); /* Reverse sign bit */
3869 16286874 to[1] = ptr[2];
3870 16286874 to[2] = ptr[1];
3871 16286874 to[3] = ptr[0];
3872 }
3873 16286874 return 4;
3874 }
3875
3876 1588858 void Field_long::sql_type(String &res) const {
3877 1588858 integer_sql_type(this, "int", &res);
3878 1588962 }
3879
3880 /****************************************************************************
3881 Field type longlong int (8 bytes)
3882 ****************************************************************************/
3883
3884 1735916 type_conversion_status Field_longlong::store(const char *from, size_t len,
3885 const CHARSET_INFO *cs) {
3886
4/6
✓ Branch 0 taken 1735917 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1624569 times.
✓ Branch 3 taken 111348 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1624572 times.
1735916 ASSERT_COLUMN_MARKED_FOR_WRITE;
3887 1735919 int conv_err = 0;
3888 1735919 type_conversion_status error = TYPE_OK;
3889 const char *end;
3890 ulonglong tmp;
3891
3892
1/2
✓ Branch 0 taken 1735940 times.
✗ Branch 1 not taken.
1735919 tmp = cs->cset->strntoull10rnd(cs, from, len, is_unsigned(), &end, &conv_err);
3893
2/2
✓ Branch 0 taken 217 times.
✓ Branch 1 taken 1735723 times.
1735940 if (conv_err == MY_ERRNO_ERANGE) {
3894
1/2
✓ Branch 0 taken 217 times.
✗ Branch 1 not taken.
217 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3895 217 error = TYPE_WARN_OUT_OF_RANGE;
3896
5/6
✓ Branch 0 taken 1735722 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116449 times.
✓ Branch 3 taken 1619273 times.
✓ Branch 4 taken 48 times.
✓ Branch 5 taken 1735674 times.
1852172 } else if (current_thd->check_for_truncated_fields &&
3897
3/4
✓ Branch 0 taken 116449 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 116401 times.
116449 check_int(cs, from, len, end, conv_err))
3898 48 error = TYPE_WARN_OUT_OF_RANGE;
3899 else
3900 1735674 error = TYPE_OK;
3901
3902
2/2
✓ Branch 0 taken 1735928 times.
✓ Branch 1 taken 11 times.
1735939 if (table->s->db_low_byte_first)
3903 1735928 int8store(ptr, tmp);
3904 else
3905 11 longlongstore(ptr, tmp);
3906 1735923 return error;
3907 }
3908
3909 3396751 type_conversion_status Field_longlong::store(double nr) {
3910
3/6
✓ Branch 0 taken 3396751 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3396751 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3396751 times.
3396751 ASSERT_COLUMN_MARKED_FOR_WRITE;
3911 3396751 type_conversion_status error = TYPE_OK;
3912 longlong res;
3913
3914 3396751 nr = rint(nr);
3915
2/2
✓ Branch 0 taken 363579 times.
✓ Branch 1 taken 3033172 times.
3396751 if (is_unsigned()) {
3916
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 363539 times.
363579 if (nr < 0) {
3917 40 res = 0;
3918 40 error = TYPE_WARN_OUT_OF_RANGE;
3919
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 363527 times.
363539 } else if (nr >= ULLONG_MAX_DOUBLE) {
3920 12 res = ~(longlong)0;
3921 12 error = TYPE_WARN_OUT_OF_RANGE;
3922 } else
3923 363527 res = double2ulonglong(nr);
3924 } else {
3925
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 3033142 times.
3033172 if (nr <= LLONG_MIN) {
3926 30 res = LLONG_MIN;
3927
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 12 times.
30 if (nr < LLONG_MIN) error = TYPE_WARN_OUT_OF_RANGE;
3928
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 3033100 times.
3033142 } else if (nr >= LLONG_MAX_DOUBLE) {
3929 42 res = LLONG_MAX;
3930
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if (nr > LLONG_MAX_DOUBLE) error = TYPE_WARN_OUT_OF_RANGE;
3931 } else
3932 3033100 res = nr;
3933 }
3934
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 3396639 times.
3396751 if (error)
3935 112 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3936
3937
1/2
✓ Branch 0 taken 3396751 times.
✗ Branch 1 not taken.
3396751 if (table->s->db_low_byte_first)
3938 3396751 int8store(ptr, res);
3939 else
3940 longlongstore(ptr, res);
3941 3396751 return error;
3942 }
3943
3944 259524744 type_conversion_status Field_longlong::store(longlong nr, bool unsigned_val) {
3945
4/6
✓ Branch 0 taken 259524756 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 259522567 times.
✓ Branch 3 taken 2189 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 259522571 times.
259524744 ASSERT_COLUMN_MARKED_FOR_WRITE;
3946 259524748 type_conversion_status error = TYPE_OK;
3947
3948
2/2
✓ Branch 0 taken 2411476 times.
✓ Branch 1 taken 257113272 times.
259524748 if (nr < 0) // Only possible error
3949 {
3950 /*
3951 if field is unsigned and value is signed (< 0) or
3952 if field is signed and value is unsigned we have an overflow
3953 */
3954
2/2
✓ Branch 0 taken 261 times.
✓ Branch 1 taken 2411215 times.
2411476 if (is_unsigned() != unsigned_val) {
3955
2/2
✓ Branch 0 taken 249 times.
✓ Branch 1 taken 39 times.
261 nr = is_unsigned() ? (ulonglong)0 : (ulonglong)LLONG_MAX;
3956 288 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
3957 288 error = TYPE_WARN_OUT_OF_RANGE;
3958 }
3959 }
3960
3961
2/2
✓ Branch 0 taken 259523549 times.
✓ Branch 1 taken 1226 times.
259524775 if (table->s->db_low_byte_first)
3962 259523549 int8store(ptr, nr);
3963 else
3964 1226 longlongstore(ptr, nr);
3965 259524784 return error;
3966 }
3967
3968 34896 double Field_longlong::val_real() const {
3969
3/6
✓ Branch 0 taken 34896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34896 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 34896 times.
34896 ASSERT_COLUMN_MARKED_FOR_READ;
3970 longlong j;
3971
1/2
✓ Branch 0 taken 34896 times.
✗ Branch 1 not taken.
34896 if (table->s->db_low_byte_first)
3972 34896 j = sint8korr(ptr);
3973 else
3974 j = longlongget(ptr);
3975
2/2
✓ Branch 0 taken 23769 times.
✓ Branch 1 taken 11127 times.
34896 if (is_unsigned()) {
3976 23769 return ulonglong2double(static_cast<ulonglong>(j));
3977 }
3978 11127 return static_cast<double>(j);
3979 }
3980
3981 393000150 longlong Field_longlong::val_int() const {
3982
4/6
✓ Branch 0 taken 393000150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 392998920 times.
✓ Branch 3 taken 1230 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 392998885 times.
393000150 ASSERT_COLUMN_MARKED_FOR_READ;
3983
2/2
✓ Branch 0 taken 392998881 times.
✓ Branch 1 taken 1234 times.
393000115 if (table->s->db_low_byte_first)
3984 392998881 return sint8korr(ptr);
3985 else
3986 1234 return longlongget(ptr);
3987 }
3988
3989 644823 String *Field_longlong::val_str(String *val_buffer, String *) const {
3990 644823 const CHARSET_INFO *cs = &my_charset_numeric;
3991 uint length;
3992 644823 uint mlength = max(field_length + 1, 22 * cs->mbmaxlen);
3993 644823 val_buffer->alloc(mlength);
3994 644823 char *to = val_buffer->ptr();
3995 longlong j;
3996
1/2
✓ Branch 0 taken 644823 times.
✗ Branch 1 not taken.
644823 if (table->s->db_low_byte_first)
3997 644823 j = sint8korr(ptr);
3998 else
3999 j = longlongget(ptr);
4000
4001
2/2
✓ Branch 0 taken 503686 times.
✓ Branch 1 taken 141137 times.
644823 length = (uint)(cs->cset->longlong10_to_str)(cs, to, mlength,
4002 644823 is_unsigned() ? 10 : -10, j);
4003 644823 val_buffer->length(length);
4004
2/2
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 644718 times.
644823 if (zerofill) prepend_zeros(val_buffer);
4005 644823 val_buffer->set_charset(cs);
4006 644823 return val_buffer;
4007 }
4008
4009 93925281 bool Field_longlong::send_to_protocol(Protocol *protocol) const {
4010
3/6
✓ Branch 0 taken 93925281 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 93925281 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 93925281 times.
93925281 ASSERT_COLUMN_MARKED_FOR_READ;
4011
2/2
✓ Branch 0 taken 17709679 times.
✓ Branch 1 taken 76215602 times.
93925281 if (is_null()) return protocol->store_null();
4012 76215602 return protocol->store_longlong(Field_longlong::val_int(), is_unsigned(),
4013
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 76215546 times.
152431204 zerofill ? field_length : 0);
4014 }
4015
4016 572313 int Field_longlong::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
4017 longlong a, b;
4018
1/2
✓ Branch 0 taken 572313 times.
✗ Branch 1 not taken.
572313 if (table->s->db_low_byte_first) {
4019 572313 a = sint8korr(a_ptr);
4020 572313 b = sint8korr(b_ptr);
4021 } else {
4022 a = longlongget(a_ptr);
4023 b = longlongget(b_ptr);
4024 }
4025
2/2
✓ Branch 0 taken 42793 times.
✓ Branch 1 taken 529520 times.
572313 if (is_unsigned())
4026 42793 return ((ulonglong)a < (ulonglong)b)
4027
2/2
✓ Branch 0 taken 29956 times.
✓ Branch 1 taken 12837 times.
72749 ? -1
4028
2/2
✓ Branch 0 taken 1789 times.
✓ Branch 1 taken 28167 times.
72749 : ((ulonglong)a > (ulonglong)b) ? 1 : 0;
4029
4/4
✓ Branch 0 taken 345945 times.
✓ Branch 1 taken 183575 times.
✓ Branch 2 taken 334481 times.
✓ Branch 3 taken 11464 times.
529520 return (a < b) ? -1 : (a > b) ? 1 : 0;
4030 }
4031
4032 3567741 size_t Field_longlong::make_sort_key(uchar *to, size_t length) const {
4033
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3567741 times.
3567741 assert(length == PACK_LENGTH);
4034 #ifdef WORDS_BIGENDIAN
4035 if (table == NULL || !table->s->db_low_byte_first)
4036 copy_integer<true>(to, length, ptr, PACK_LENGTH, is_unsigned());
4037 else
4038 #endif
4039 3567741 copy_integer<false>(to, length, ptr, PACK_LENGTH, is_unsigned());
4040 3567741 return PACK_LENGTH;
4041 }
4042
4043 2365564 void Field_longlong::sql_type(String &res) const {
4044 2365564 integer_sql_type(this, "bigint", &res);
4045 2365567 }
4046
4047 /*
4048 Floating-point numbers
4049 */
4050
4051 3849956 uchar *Field_real::pack(uchar *to, const uchar *from, size_t max_length) const {
4052
1/2
✓ Branch 0 taken 3849956 times.
✗ Branch 1 not taken.
3849956 DBUG_TRACE;
4053 #ifdef WORDS_BIGENDIAN
4054 if (!table->s->db_low_byte_first) {
4055 size_t len = std::min<size_t>(pack_length(), max_length);
4056 for (size_t i = 0; i < len; ++i) {
4057 to[i] = from[pack_length() - i - 1];
4058 }
4059 return to + pack_length();
4060 } else
4061 #endif
4062
1/2
✓ Branch 0 taken 3849956 times.
✗ Branch 1 not taken.
7699912 return Field::pack(to, from, max_length);
4063 3849956 }
4064
4065 2330493 const uchar *Field_real::unpack(uchar *to, const uchar *from, uint param_data) {
4066
1/2
✓ Branch 0 taken 2330493 times.
✗ Branch 1 not taken.
2330493 DBUG_TRACE;
4067 #ifdef WORDS_BIGENDIAN
4068 if (!table->s->db_low_byte_first) {
4069 const uchar *dptr = from + pack_length();
4070 while (dptr-- > from) *to++ = *dptr;
4071 return from + pack_length();
4072 } else
4073 #endif
4074
1/2
✓ Branch 0 taken 2330493 times.
✗ Branch 1 not taken.
4660986 return Field::unpack(to, from, param_data);
4075 2330493 }
4076
4077 2 type_conversion_status Field_real::store_time(MYSQL_TIME *ltime, uint8) {
4078 2 double nr = TIME_to_double(*ltime);
4079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 return store(ltime->neg ? -nr : nr);
4080 }
4081
4082 /****************************************************************************
4083 single precision float
4084 ****************************************************************************/
4085
4086 51349 type_conversion_status Field_float::store(const char *from, size_t len,
4087 const CHARSET_INFO *cs) {
4088
1/2
✓ Branch 0 taken 51349 times.
✗ Branch 1 not taken.
51349 THD *thd = current_thd;
4089
4090 int conv_error;
4091 51349 type_conversion_status err = TYPE_OK;
4092 const char *end;
4093
1/2
✓ Branch 0 taken 51349 times.
✗ Branch 1 not taken.
51349 double nr = my_strntod(cs, from, len, &end, &conv_error);
4094
6/6
✓ Branch 0 taken 51326 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 51302 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 64 times.
✓ Branch 5 taken 51285 times.
102651 if (conv_error != 0 || end == from ||
4095
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 51283 times.
51302 (((uint)(end - from) != len &&
4096
3/4
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 2 times.
19 !check_if_only_end_space(cs, end, from + len) &&
4097
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 thd->check_for_truncated_fields))) {
4098
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 set_warning(Sql_condition::SL_WARNING,
4099
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 41 times.
64 (conv_error ? ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED),
4100 1);
4101
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 41 times.
64 err = conv_error ? TYPE_WARN_OUT_OF_RANGE : TYPE_WARN_TRUNCATED;
4102 }
4103
1/2
✓ Branch 0 taken 51349 times.
✗ Branch 1 not taken.
51349 Field_float::store(nr);
4104 51349 return err;
4105 }
4106
4107 890669 type_conversion_status Field_float::store(double nr) {
4108
4/6
✓ Branch 0 taken 890669 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 888406 times.
✓ Branch 3 taken 2263 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 888406 times.
890669 ASSERT_COLUMN_MARKED_FOR_WRITE;
4109 const type_conversion_status error =
4110
2/2
✓ Branch 0 taken 238 times.
✓ Branch 1 taken 890431 times.
890669 truncate(&nr, FLT_MAX) ? TYPE_WARN_OUT_OF_RANGE : TYPE_OK;
4111
4112 890669 float j = (float)nr;
4113
4114
2/2
✓ Branch 0 taken 890629 times.
✓ Branch 1 taken 40 times.
890669 if (table->s->db_low_byte_first)
4115 890629 float4store(ptr, j);
4116 else
4117 40 floatstore(ptr, j);
4118 890669 return error;
4119 }
4120
4121 5137 type_conversion_status Field_float::store(longlong nr, bool unsigned_val) {
4122
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 5108 times.
5137 return Field_float::store(unsigned_val ? ulonglong2double((ulonglong)nr)
4123 5137 : (double)nr);
4124 }
4125
4126 46406 double Field_float::val_real() const {
4127
4/6
✓ Branch 0 taken 46406 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46379 times.
✓ Branch 3 taken 27 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 46379 times.
46406 ASSERT_COLUMN_MARKED_FOR_READ;
4128
2/2
✓ Branch 0 taken 46379 times.
✓ Branch 1 taken 27 times.
46406 if (table->s->db_low_byte_first)
4129 46379 return double{float4get(ptr)};
4130 else
4131 27 return double{floatget(ptr)};
4132 }
4133
4134 85 longlong Field_float::val_int() const {
4135 float j;
4136
1/2
✓ Branch 0 taken 85 times.
✗ Branch 1 not taken.
85 if (table->s->db_low_byte_first)
4137 85 j = float4get(ptr);
4138 else
4139 j = floatget(ptr);
4140 85 return (longlong)rint(j);
4141 }
4142
4143 17334 String *Field_float::val_str(String *val_buffer, String *) const {
4144
4/6
✓ Branch 0 taken 17334 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15102 times.
✓ Branch 3 taken 2232 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 15102 times.
17334 ASSERT_COLUMN_MARKED_FOR_READ;
4145
3/4
✓ Branch 0 taken 1779 times.
✓ Branch 1 taken 15555 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1779 times.
17334 assert(!zerofill || field_length <= MAX_FIELD_CHARLENGTH);
4146 float nr;
4147
3/4
✓ Branch 0 taken 17334 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17324 times.
✓ Branch 3 taken 10 times.
17334 if (table && table->s->db_low_byte_first)
4148 17324 nr = float4get(ptr);
4149 else
4150 10 nr = floatget(ptr);
4151
4152 17334 uint to_length = 70;
4153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17334 times.
17334 if (val_buffer->alloc(to_length)) {
4154 my_error(ER_OUT_OF_RESOURCES, MYF(0));
4155 return val_buffer;
4156 }
4157
4158 17334 char *to = val_buffer->ptr();
4159 size_t len;
4160
4161
2/2
✓ Branch 0 taken 13949 times.
✓ Branch 1 taken 3385 times.
17334 if (dec >= DECIMAL_NOT_SPECIFIED)
4162 13949 len = my_gcvt(nr, MY_GCVT_ARG_FLOAT, MAX_FLOAT_STR_LENGTH, to, nullptr);
4163 else {
4164 /*
4165 We are safe here because the buffer length is 70, and
4166 fabs(float) < 10^39, dec < DECIMAL_NOT_SPECIFIED. So the resulting string
4167 will be not longer than 69 chars + terminating '\0'.
4168 */
4169 3385 len = my_fcvt(nr, dec, to, nullptr);
4170 }
4171 17334 val_buffer->length((uint)len);
4172
2/2
✓ Branch 0 taken 1779 times.
✓ Branch 1 taken 15555 times.
17334 if (zerofill) prepend_zeros(val_buffer);
4173 17334 val_buffer->set_charset(&my_charset_numeric);
4174 17334 return val_buffer;
4175 }
4176
4177 545 int Field_float::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
4178 float a, b;
4179
1/2
✓ Branch 0 taken 545 times.
✗ Branch 1 not taken.
545 if (table->s->db_low_byte_first) {
4180 545 a = float4get(a_ptr);
4181 545 b = float4get(b_ptr);
4182 } else {
4183 a = floatget(a_ptr);
4184 b = floatget(b_ptr);
4185 }
4186
4/4
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 390 times.
✓ Branch 2 taken 95 times.
✓ Branch 3 taken 295 times.
545 return (a < b) ? -1 : (a > b) ? 1 : 0;
4187 }
4188
4189 3923 size_t Field_float::make_sort_key(uchar *to,
4190 size_t length [[maybe_unused]]) const {
4191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3923 times.
3923 assert(length == sizeof(float));
4192 float nr;
4193
2/2
✓ Branch 0 taken 3921 times.
✓ Branch 1 taken 2 times.
3923 if (table->s->db_low_byte_first)
4194 3921 nr = float4get(ptr);
4195 else
4196 2 nr = floatget(ptr);
4197
4198 /*
4199 -0.0 and +0.0 compare identically, so make sure they use exactly the same
4200 bit pattern.
4201 */
4202
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3917 times.
3923 if (nr == 0.0f) nr = 0.0f;
4203
4204 /*
4205 Positive floats sort exactly as ints; negative floats need
4206 bit flipping. The bit flipping sets the upper bit to 0
4207 unconditionally, so put 1 in there for positive numbers
4208 (so they sort later for our unsigned comparison).
4209 NOTE: This does not sort infinities or NaN correctly.
4210 */
4211 int32 nr_int;
4212 3923 memcpy(&nr_int, &nr, sizeof(nr));
4213 3923 nr_int = (nr_int ^ (nr_int >> 31)) | ((~nr_int) & 0x80000000);
4214
1/2
✓ Branch 0 taken 3923 times.
✗ Branch 1 not taken.
3923 store32be(to, nr_int);
4215
4216 3923 return sizeof(float);
4217 }
4218
4219 25492 bool Field_float::send_to_protocol(Protocol *protocol) const {
4220
3/6
✓ Branch 0 taken 25492 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25492 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 25492 times.
25492 ASSERT_COLUMN_MARKED_FOR_READ;
4221
2/2
✓ Branch 0 taken 748 times.
✓ Branch 1 taken 24744 times.
25492 if (is_null()) return protocol->store_null();
4222 24744 return protocol->store_float(static_cast<float>(Field_float::val_real()), dec,
4223
2/2
✓ Branch 0 taken 9066 times.
✓ Branch 1 taken 15678 times.
49488 zerofill ? field_length : 0);
4224 }
4225
4226 /**
4227 Save the field metadata for float fields.
4228
4229 Saves the pack length in the first byte.
4230
4231 @param metadata_ptr First byte of field metadata
4232
4233 @returns number of bytes written to metadata_ptr
4234 */
4235 18505 int Field_float::do_save_field_metadata(uchar *metadata_ptr) const {
4236 18505 *metadata_ptr = pack_length();
4237 18505 return 1;
4238 }
4239
4240 55821 void Field_float::sql_type(String &res) const {
4241
2/2
✓ Branch 0 taken 17075 times.
✓ Branch 1 taken 38746 times.
55821 if (dec == DECIMAL_NOT_SPECIFIED) {
4242 17075 res.set_ascii(STRING_WITH_LEN("float"));
4243 } else {
4244 38746 const CHARSET_INFO *cs = res.charset();
4245 38746 res.length(cs->cset->snprintf(cs, res.ptr(), res.alloced_length(),
4246 38746 "float(%d,%d)", (int)field_length, dec));
4247 }
4248 55821 append_zerofill_and_unsigned(this, &res);
4249 55821 }
4250
4251 /****************************************************************************
4252 double precision floating point numbers
4253 ****************************************************************************/
4254
4255 145356 type_conversion_status Field_double::store(const char *from, size_t len,
4256 const CHARSET_INFO *cs) {
4257
1/2
✓ Branch 0 taken 145356 times.
✗ Branch 1 not taken.
145356 THD *thd = current_thd;
4258
4259 int conv_error;
4260 145356 type_conversion_status error = TYPE_OK;
4261 const char *end;
4262
1/2
✓ Branch 0 taken 145356 times.
✗ Branch 1 not taken.
145356 double nr = my_strntod(cs, from, len, &end, &conv_error);
4263
6/6
✓ Branch 0 taken 145329 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 5552 times.
✓ Branch 3 taken 139777 times.
✓ Branch 4 taken 139821 times.
✓ Branch 5 taken 5535 times.
150908 if (conv_error != 0 || end == from ||
4264
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 5533 times.
5552 (((uint)(end - from) != len &&
4265
3/4
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 2 times.
19 !check_if_only_end_space(cs, end, from + len) &&
4266
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 thd->check_for_truncated_fields))) {
4267
1/2
✓ Branch 0 taken 139821 times.
✗ Branch 1 not taken.
139821 set_warning(Sql_condition::SL_WARNING,
4268
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 139794 times.
139821 (conv_error ? ER_WARN_DATA_OUT_OF_RANGE : WARN_DATA_TRUNCATED),
4269 1);
4270
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 139794 times.
139821 error = conv_error ? TYPE_WARN_OUT_OF_RANGE : TYPE_WARN_TRUNCATED;
4271 }
4272
1/2
✓ Branch 0 taken 145356 times.
✗ Branch 1 not taken.
145356 Field_double::store(nr);
4273 145356 return error;
4274 }
4275
4276 5014785 type_conversion_status Field_double::store(double nr) {
4277
4/6
✓ Branch 0 taken 5014785 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5013638 times.
✓ Branch 3 taken 1147 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5013639 times.
5014785 ASSERT_COLUMN_MARKED_FOR_WRITE;
4278 const type_conversion_status error =
4279
2/2
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 5014683 times.
5014786 truncate(&nr, DBL_MAX) ? TYPE_WARN_OUT_OF_RANGE : TYPE_OK;
4280
4281
2/2
✓ Branch 0 taken 5014736 times.
✓ Branch 1 taken 50 times.
5014786 if (table->s->db_low_byte_first)
4282 5014736 float8store(ptr, nr);
4283 else
4284 50 doublestore(ptr, nr);
4285 5014786 return error;
4286 }
4287
4288 8467 type_conversion_status Field_double::store(longlong nr, bool unsigned_val) {
4289
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 7447 times.
8467 return Field_double::store(unsigned_val ? ulonglong2double((ulonglong)nr)
4290 8467 : (double)nr);
4291 }
4292
4293 /**
4294 If a field has fixed length, truncate the double argument pointed to by 'nr'
4295 appropriately.
4296 Also ensure that the argument is within [min_value; max_value] where
4297 min_value == 0 if unsigned_flag is set, else -max_value.
4298
4299 @param[in,out] nr the real number (FLOAT or DOUBLE) to be truncated
4300 @param[in] max_value the maximum (absolute) value of the real type
4301
4302 @returns truncation result
4303 */
4304
4305 5909976 Field_real::Truncate_result Field_real::truncate(double *nr, double max_value) {
4306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5909976 times.
5909976 if (std::isnan(*nr)) {
4307 *nr = 0;
4308 set_null();
4309 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
4310 return TR_POSITIVE_OVERFLOW;
4311
6/6
✓ Branch 0 taken 7204 times.
✓ Branch 1 taken 5902772 times.
✓ Branch 2 taken 136 times.
✓ Branch 3 taken 7068 times.
✓ Branch 4 taken 136 times.
✓ Branch 5 taken 5909840 times.
5909976 } else if (is_unsigned() && *nr < 0) {
4312 136 *nr = 0;
4313 136 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
4314 136 return TR_NEGATIVE_OVERFLOW;
4315 }
4316
4317
2/2
✓ Branch 0 taken 983540 times.
✓ Branch 1 taken 4926300 times.
5909840 if (!not_fixed) {
4318 983540 double orig_max_value = max_value;
4319 983540 uint order = field_length - dec;
4320 983540 uint step = array_elements(log_10) - 1;
4321 983540 max_value = 1.0;
4322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 983540 times.
983540 for (; order > step; order -= step) max_value *= log_10[step];
4323 983540 max_value *= log_10[order];
4324 983540 max_value -= 1.0 / log_10[dec];
4325 983540 max_value = std::min(max_value, orig_max_value);
4326
4327 /* Check for infinity so we don't get NaN in calculations */
4328
1/2
✓ Branch 0 taken 983540 times.
✗ Branch 1 not taken.
983540 if (!std::isinf(*nr)) {
4329 983540 double tmp = rint((*nr - floor(*nr)) * log_10[dec]) / log_10[dec];
4330 983540 *nr = floor(*nr) + tmp;
4331 }
4332 }
4333
4334
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 5909726 times.
5909840 if (*nr < -max_value) {
4335 114 *nr = -max_value;
4336 114 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
4337 114 return TR_NEGATIVE_OVERFLOW;
4338
2/2
✓ Branch 0 taken 214 times.
✓ Branch 1 taken 5909512 times.
5909726 } else if (*nr > max_value) {
4339 214 *nr = max_value;
4340 214 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
4341 214 return TR_POSITIVE_OVERFLOW;
4342 }
4343
4344 5909512 return TR_OK;
4345 }
4346
4347 701837 type_conversion_status Field_real::store_decimal(const my_decimal *dm) {
4348 double dbl;
4349
1/2
✓ Branch 0 taken 701837 times.
✗ Branch 1 not taken.
701837 my_decimal2double(E_DEC_FATAL_ERROR, dm, &dbl);
4350
1/2
✓ Branch 0 taken 701837 times.
✗ Branch 1 not taken.
1403674 return store(dbl);
4351 }
4352
4353 11371222 double Field_double::val_real() const {
4354
4/6
✓ Branch 0 taken 11371222 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11371172 times.
✓ Branch 3 taken 50 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 11371172 times.
11371222 ASSERT_COLUMN_MARKED_FOR_READ;
4355
2/2
✓ Branch 0 taken 11371172 times.
✓ Branch 1 taken 50 times.
11371222 if (table->s->db_low_byte_first)
4356 11371172 return float8get(ptr);
4357 else
4358 50 return doubleget(ptr);
4359 }
4360
4361 2231 longlong Field_double::val_int() const {
4362
3/6
✓ Branch 0 taken 2231 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2231 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2231 times.
2231 ASSERT_COLUMN_MARKED_FOR_READ;
4363 double j;
4364 longlong res;
4365
1/2
✓ Branch 0 taken 2231 times.
✗ Branch 1 not taken.
2231 if (table->s->db_low_byte_first)
4366 2231 j = float8get(ptr);
4367 else
4368 j = doubleget(ptr);
4369 /* Check whether we fit into longlong range */
4370
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 2206 times.
2231 if (j <= LLONG_MIN) {
4371 25 res = (longlong)LLONG_MIN;
4372 25 goto warn;
4373 }
4374
2/2
✓ Branch 0 taken 284 times.
✓ Branch 1 taken 1922 times.
2206 if (j >= LLONG_MAX_DOUBLE) {
4375 284 res = LLONG_MAX;
4376 284 goto warn;
4377 }
4378 1922 return (longlong)rint(j);
4379
4380 309 warn : {
4381 char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
4382 309 String tmp(buf, sizeof(buf), &my_charset_latin1), *str;
4383
1/2
✓ Branch 0 taken 309 times.
✗ Branch 1 not taken.
309 str = val_str(&tmp, nullptr);
4384
1/2
✓ Branch 0 taken 309 times.
✗ Branch 1 not taken.
309 ErrConvString err(str);
4385 309 push_warning_printf(
4386
2/4
✓ Branch 0 taken 309 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 309 times.
✗ Branch 3 not taken.
309 current_thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE,
4387
2/4
✓ Branch 0 taken 309 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 309 times.
✗ Branch 3 not taken.
309 ER_THD(current_thd, ER_TRUNCATED_WRONG_VALUE), "INTEGER", err.ptr());
4388 309 }
4389 309 return res;
4390 }
4391
4392 114 my_decimal *Field_real::val_decimal(my_decimal *decimal_value) const {
4393
3/6
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 114 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 114 times.
114 ASSERT_COLUMN_MARKED_FOR_READ;
4394 114 double2my_decimal(E_DEC_FATAL_ERROR, val_real(), decimal_value);
4395 114 return decimal_value;
4396 }
4397
4398 62 bool Field_real::get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const {
4399 62 return my_double_to_datetime_with_warn(val_real(), ltime, fuzzydate);
4400 }
4401
4402 46 bool Field_real::get_time(MYSQL_TIME *ltime) const {
4403 46 return my_double_to_time_with_warn(val_real(), ltime);
4404 }
4405
4406 16629 String *Field_double::val_str(String *val_buffer, String *) const {
4407
4/6
✓ Branch 0 taken 16629 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15488 times.
✓ Branch 3 taken 1141 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 15488 times.
16629 ASSERT_COLUMN_MARKED_FOR_READ;
4408
3/4
✓ Branch 0 taken 926 times.
✓ Branch 1 taken 15703 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 926 times.
16629 assert(!zerofill || field_length <= MAX_FIELD_CHARLENGTH);
4409 double nr;
4410
2/4
✓ Branch 0 taken 16629 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16629 times.
✗ Branch 3 not taken.
16629 if (table && table->s->db_low_byte_first)
4411 16629 nr = float8get(ptr);
4412 else
4413 nr = doubleget(ptr);
4414 16629 uint to_length = DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE;
4415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16629 times.
16629 if (val_buffer->alloc(to_length)) {
4416 my_error(ER_OUT_OF_RESOURCES, MYF(0));
4417 return val_buffer;
4418 }
4419
4420 16629 char *to = val_buffer->ptr();
4421 size_t len;
4422
4423
2/2
✓ Branch 0 taken 13350 times.
✓ Branch 1 taken 3279 times.
16629 if (dec >= DECIMAL_NOT_SPECIFIED)
4424 // +2 to avoid rounding errors when converting back to double.
4425 len =
4426 13350 my_gcvt(nr, MY_GCVT_ARG_DOUBLE, MAX_DOUBLE_STR_LENGTH + 2, to, nullptr);
4427 else
4428 3279 len = my_fcvt(nr, dec, to, nullptr);
4429
4430 16629 val_buffer->length((uint)len);
4431
2/2
✓ Branch 0 taken 926 times.
✓ Branch 1 taken 15703 times.
16629 if (zerofill) prepend_zeros(val_buffer);
4432 16629 val_buffer->set_charset(&my_charset_numeric);
4433 16629 return val_buffer;
4434 }
4435
4436 747391 bool Field_double::send_to_protocol(Protocol *protocol) const {
4437
2/2
✓ Branch 0 taken 4627 times.
✓ Branch 1 taken 742764 times.
747391 if (is_null()) return protocol->store_null();
4438 742764 return protocol->store_double(Field_double::val_real(), dec,
4439
2/2
✓ Branch 0 taken 5065 times.
✓ Branch 1 taken 737699 times.
1485528 zerofill ? field_length : 0);
4440 }
4441
4442 1215 int Field_double::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
4443 double a, b;
4444
1/2
✓ Branch 0 taken 1215 times.
✗ Branch 1 not taken.
1215 if (table->s->db_low_byte_first) {
4445 1215 a = float8get(a_ptr);
4446 1215 b = float8get(b_ptr);
4447 } else {
4448 a = doubleget(a_ptr);
4449 b = doubleget(b_ptr);
4450 }
4451
4/4
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 1003 times.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 883 times.
1215 return (a < b) ? -1 : (a > b) ? 1 : 0;
4452 }
4453
4454 /* The following should work for IEEE */
4455
4456 6120 size_t Field_double::make_sort_key(uchar *to, size_t length) const {
4457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6120 times.
6120 assert(length == sizeof(double));
4458 double nr;
4459
2/2
✓ Branch 0 taken 6118 times.
✓ Branch 1 taken 2 times.
6120 if (table->s->db_low_byte_first)
4460 6118 nr = float8get(ptr);
4461 else
4462 2 nr = doubleget(ptr);
4463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6120 times.
6120 if (length < 8) {
4464 uchar buff[8];
4465 change_double_for_sort(nr, buff);
4466 memcpy(to, buff, length);
4467 } else
4468 6120 change_double_for_sort(nr, to);
4469 6120 return sizeof(double);
4470 }
4471
4472 /**
4473 Save the field metadata for double fields.
4474
4475 Saves the pack length in the first byte of the field metadata array
4476 at index of *metadata_ptr.
4477
4478 @param metadata_ptr First byte of field metadata
4479
4480 @returns number of bytes written to metadata_ptr
4481 */
4482 21282 int Field_double::do_save_field_metadata(uchar *metadata_ptr) const {
4483 21282 *metadata_ptr = pack_length();
4484 21282 return 1;
4485 }
4486
4487 16357 void Field_double::sql_type(String &res) const {
4488 16357 const CHARSET_INFO *cs = res.charset();
4489
2/2
✓ Branch 0 taken 10795 times.
✓ Branch 1 taken 5562 times.
16357 if (dec == DECIMAL_NOT_SPECIFIED) {
4490 10795 res.set_ascii(STRING_WITH_LEN("double"));
4491 } else {
4492 5562 res.length(cs->cset->snprintf(cs, res.ptr(), res.alloced_length(),
4493 5562 "double(%d,%d)", (int)field_length, dec));
4494 }
4495 16357 append_zerofill_and_unsigned(this, &res);
4496 16357 }
4497
4498 /****************************************************************************
4499 ** Common code for all temporal data types: DATE, DATETIME, TIMESTAMP, TIME
4500 *****************************************************************************/
4501
4502 10025182 my_time_flags_t Field_temporal::date_flags() const {
4503 10025182 return date_flags(current_thd);
4504 }
4505
4506 18368 uint Field_temporal::is_equal(const Create_field *new_field) const {
4507
2/2
✓ Branch 0 taken 18311 times.
✓ Branch 1 taken 57 times.
36679 return new_field->sql_type == real_type() &&
4508
2/2
✓ Branch 0 taken 18250 times.
✓ Branch 1 taken 61 times.
36679 new_field->decimals == decimals();
4509 }
4510
4511 66 my_decimal *Field_temporal::val_decimal(my_decimal *decimal_value) const {
4512
3/6
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 66 times.
66 ASSERT_COLUMN_MARKED_FOR_READ;
4513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 assert(decimals() == 0);
4514 66 int2my_decimal(E_DEC_FATAL_ERROR, val_int(), false, decimal_value);
4515 66 return decimal_value;
4516 }
4517
4518 5644 bool Field_temporal::set_warnings(const ErrConvString &str, int warnings) {
4519 5644 bool truncate_incremented = false;
4520 5644 enum_mysql_timestamp_type ts_type = field_type_to_timestamp_type(type());
4521
4522
2/2
✓ Branch 0 taken 1341 times.
✓ Branch 1 taken 4303 times.
5644 if (warnings & MYSQL_TIME_WARN_TRUNCATED) {
4523
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 1293 times.
1341 if (set_datetime_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED,
4524 1341 str, ts_type, !truncate_incremented))
4525 48 return true;
4526 1293 truncate_incremented = true;
4527 }
4528
2/2
✓ Branch 0 taken 2462 times.
✓ Branch 1 taken 3134 times.
5596 if (warnings & (MYSQL_TIME_WARN_OUT_OF_RANGE | MYSQL_TIME_WARN_ZERO_DATE |
4529 MYSQL_TIME_WARN_ZERO_IN_DATE)) {
4530
2/2
✓ Branch 0 taken 222 times.
✓ Branch 1 taken 2240 times.
2462 if (set_datetime_warning(Sql_condition::SL_WARNING,
4531 ER_WARN_DATA_OUT_OF_RANGE, str, ts_type,
4532 2462 !truncate_incremented))
4533 222 return true;
4534 2240 truncate_incremented = true;
4535 }
4536
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 5361 times.
5374 if (warnings & MYSQL_TIME_WARN_INVALID_TIMESTAMP) {
4537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if (set_datetime_warning(Sql_condition::SL_WARNING,
4538 ER_WARN_INVALID_TIMESTAMP, str, ts_type,
4539 13 !truncate_incremented))
4540 return true;
4541 13 truncate_incremented = true;
4542 }
4543
2/2
✓ Branch 0 taken 1829 times.
✓ Branch 1 taken 3545 times.
5374 if ((warnings & MYSQL_TIME_NOTE_TRUNCATED) &&
4544
1/2
✓ Branch 0 taken 1829 times.
✗ Branch 1 not taken.
1829 !(warnings & MYSQL_TIME_WARN_TRUNCATED)) {
4545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1829 times.
1829 if (set_datetime_warning(Sql_condition::SL_NOTE, WARN_DATA_TRUNCATED, str,
4546 1829 ts_type, !truncate_incremented))
4547 return true;
4548 }
4549 5374 return false;
4550 }
4551
4552 1855644 type_conversion_status Field_temporal::store(longlong nr, bool unsigned_val) {
4553
5/6
✓ Branch 0 taken 1855642 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1855584 times.
✓ Branch 3 taken 58 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1855584 times.
1855644 ASSERT_COLUMN_MARKED_FOR_WRITE;
4554 1855644 int warnings = 0;
4555 MYSQL_TIME ltime;
4556 type_conversion_status error =
4557
1/2
✓ Branch 0 taken 1855644 times.
✗ Branch 1 not taken.
1855644 convert_number_to_TIME(nr, unsigned_val, 0, &ltime, &warnings);
4558
3/4
✓ Branch 0 taken 507 times.
✓ Branch 1 taken 1855137 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 507 times.
1855644 if (error == TYPE_OK || error == TYPE_NOTE_TRUNCATED)
4559
1/2
✓ Branch 0 taken 1855137 times.
✗ Branch 1 not taken.
1855137 error = store_internal(&ltime, &warnings);
4560 else {
4561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 507 times.
507 assert(warnings != 0); // Must be set by convert_number_to_TIME
4562
4563
4/4
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 476 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 497 times.
538 if (warnings & (MYSQL_TIME_WARN_ZERO_DATE | MYSQL_TIME_WARN_ZERO_IN_DATE) &&
4564
3/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 21 times.
31 !current_thd->is_strict_mode())
4565 10 error = TYPE_NOTE_TIME_TRUNCATED;
4566 }
4567
8/10
✓ Branch 0 taken 536 times.
✓ Branch 1 taken 1855108 times.
✓ Branch 2 taken 536 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 536 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 20 times.
✓ Branch 7 taken 516 times.
✓ Branch 8 taken 20 times.
✓ Branch 9 taken 1855624 times.
1855644 if (warnings && set_warnings(ErrConvString(nr, unsigned_val), warnings))
4568 20 return TYPE_ERR_BAD_VALUE;
4569
4570 1855624 return error;
4571 }
4572
4573 1320 type_conversion_status Field_temporal::store_lldiv_t(const lldiv_t *lld,
4574 int *warnings) {
4575
4/6
✓ Branch 0 taken 1318 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1318 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1318 times.
1320 ASSERT_COLUMN_MARKED_FOR_WRITE;
4576 type_conversion_status error;
4577 MYSQL_TIME ltime;
4578
1/2
✓ Branch 0 taken 1320 times.
✗ Branch 1 not taken.
1320 error = convert_number_to_TIME(lld->quot, false, static_cast<int>(lld->rem),
4579 &ltime, warnings);
4580
4/4
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 1086 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 222 times.
1320 if (error == TYPE_OK || error == TYPE_NOTE_TRUNCATED)
4581
1/2
✓ Branch 0 taken 1098 times.
✗ Branch 1 not taken.
1098 error = store_internal_adjust_frac(&ltime, warnings);
4582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 222 times.
222 else if (!*warnings) {
4583 assert(warnings != nullptr); // Must be set by convert_number_to_TIME
4584 if (((*warnings & MYSQL_TIME_WARN_ZERO_DATE) != 0 ||
4585 (*warnings & MYSQL_TIME_WARN_ZERO_IN_DATE) != 0) &&
4586 !current_thd->is_strict_mode())
4587 error = TYPE_NOTE_TIME_TRUNCATED;
4588 }
4589
4590 1320 return error;
4591 }
4592
4593 794 type_conversion_status Field_temporal::store_decimal(
4594 const my_decimal *decimal) {
4595
4/6
✓ Branch 0 taken 793 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 793 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 793 times.
794 ASSERT_COLUMN_MARKED_FOR_WRITE;
4596 lldiv_t lld;
4597 794 int warnings = 0;
4598 /* Pass 0 in the first argument, not to produce warnings automatically */
4599
1/2
✓ Branch 0 taken 794 times.
✗ Branch 1 not taken.
794 my_decimal2lldiv_t(0, decimal, &lld);
4600
1/2
✓ Branch 0 taken 794 times.
✗ Branch 1 not taken.
794 const type_conversion_status error = store_lldiv_t(&lld, &warnings);
4601
8/10
✓ Branch 0 taken 170 times.
✓ Branch 1 taken 624 times.
✓ Branch 2 taken 170 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 170 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 165 times.
✓ Branch 8 taken 5 times.
✓ Branch 9 taken 789 times.
794 if (warnings && set_warnings(ErrConvString(decimal), warnings))
4602 5 return TYPE_ERR_BAD_VALUE;
4603
4604 789 return error;
4605 }
4606
4607 526 type_conversion_status Field_temporal::store(double nr) {
4608
4/6
✓ Branch 0 taken 525 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 525 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 525 times.
526 ASSERT_COLUMN_MARKED_FOR_WRITE;
4609 526 int warnings = 0;
4610 lldiv_t lld;
4611
1/2
✓ Branch 0 taken 526 times.
✗ Branch 1 not taken.
526 double2lldiv_t(nr, &lld);
4612
1/2
✓ Branch 0 taken 526 times.
✗ Branch 1 not taken.
526 const type_conversion_status error = store_lldiv_t(&lld, &warnings);
4613
8/10
✓ Branch 0 taken 131 times.
✓ Branch 1 taken 395 times.
✓ Branch 2 taken 131 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 131 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 127 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 522 times.
526 if (warnings && set_warnings(ErrConvString(nr), warnings))
4614 4 return TYPE_ERR_BAD_VALUE;
4615
4616 522 return error;
4617 }
4618
4619 /**
4620 Store string into a date/time/datetime field.
4621
4622 @param str Date/time string
4623 @param len Length of the string
4624 @param cs Character set of the string
4625
4626 @retval TYPE_OK Storage of value went fine without warnings or errors
4627 @retval !TYPE_OK Warning/error as indicated by type_conversion_status enum
4628 value
4629 */
4630 113953 type_conversion_status Field_temporal::store(const char *str, size_t len,
4631 const CHARSET_INFO *cs) {
4632
5/6
✓ Branch 0 taken 113952 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 92709 times.
✓ Branch 3 taken 21243 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 92709 times.
113953 ASSERT_COLUMN_MARKED_FOR_WRITE;
4633 113953 type_conversion_status error = TYPE_OK;
4634 MYSQL_TIME ltime;
4635 113953 MYSQL_TIME_STATUS status;
4636
3/4
✓ Branch 0 taken 113953 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2350 times.
✓ Branch 3 taken 111603 times.
113953 if (convert_str_to_TIME(str, len, cs, &ltime, &status)) {
4637 /*
4638 When convert_str_to_TIME() returns error, ltime has been set to
4639 0 so there's nothing to store in the field.
4640 */
4641
1/2
✓ Branch 0 taken 2350 times.
✗ Branch 1 not taken.
2350 reset();
4642 4700 if (status.warnings &
4643
4/4
✓ Branch 0 taken 1504 times.
✓ Branch 1 taken 846 times.
✓ Branch 2 taken 121 times.
✓ Branch 3 taken 2229 times.
3854 (MYSQL_TIME_WARN_ZERO_DATE | MYSQL_TIME_WARN_ZERO_IN_DATE) &&
4644
3/4
✓ Branch 0 taken 1504 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121 times.
✓ Branch 3 taken 1383 times.
1504 !current_thd->is_strict_mode())
4645 121 error = TYPE_NOTE_TIME_TRUNCATED;
4646 else
4647 2229 error = TYPE_ERR_BAD_VALUE;
4648 } else {
4649
2/4
✓ Branch 0 taken 111603 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 111603 times.
✗ Branch 3 not taken.
111603 check_deprecated_datetime_format(current_thd, cs, status);
4650
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 111525 times.
111603 if (ltime.time_type == MYSQL_TIMESTAMP_DATETIME_TZ) {
4651 /*
4652 Convert the timestamp with timezone to without timezone. This is a
4653 lossy conversion for edge cases like for the repeat hour of the
4654 DST switch, but useful for the boundary conditions check.
4655 */
4656 78 MYSQL_TIME tmp_ltime = ltime;
4657
4/6
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 74 times.
78 if (convert_time_zone_displacement(current_thd->time_zone(), &tmp_ltime))
4658 4 return TYPE_ERR_BAD_VALUE;
4659 // check for boundary conditions by converting to a timeval
4660 my_timeval tm_not_used;
4661
2/4
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 74 times.
74 if (datetime_with_no_zero_in_date_to_timeval(
4662
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 &tmp_ltime, *current_thd->time_zone(), &tm_not_used,
4663 &status.warnings)) {
4664 if (status.warnings &&
4665 set_warnings(ErrConvString(str, len, cs), status.warnings))
4666 return TYPE_WARN_OUT_OF_RANGE;
4667 return TYPE_WARN_OUT_OF_RANGE;
4668 }
4669 }
4670 111599 error = time_warning_to_type_conversion_status(status.warnings);
4671 const type_conversion_status tmp_error =
4672
1/2
✓ Branch 0 taken 111599 times.
✗ Branch 1 not taken.
111599 store_internal_adjust_frac(&ltime, &status.warnings);
4673
4674 // Return the most serious error of the two, see type_conversion_status
4675
2/2
✓ Branch 0 taken 1420 times.
✓ Branch 1 taken 110179 times.
111599 if (tmp_error > error) error = tmp_error;
4676 }
4677
2/2
✓ Branch 0 taken 3997 times.
✓ Branch 1 taken 109952 times.
117946 if (status.warnings &&
4678
6/8
✓ Branch 0 taken 3997 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3997 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 149 times.
✓ Branch 5 taken 3848 times.
✓ Branch 6 taken 149 times.
✓ Branch 7 taken 113800 times.
117946 set_warnings(ErrConvString(str, len, cs), status.warnings))
4679 149 return TYPE_ERR_BAD_VALUE;
4680
4681 113800 return error;
4682 }
4683
4684 1855634 longlong Field_temporal::convert_number_to_datetime(longlong nr, bool,
4685 MYSQL_TIME *ltime,
4686 int *warnings) {
4687 /*
4688 Note, number_to_datetime can return a result different from nr:
4689 e.g. 111111 -> 20111111000000
4690 */
4691 1855634 longlong tmp = number_to_datetime(nr, ltime, date_flags(), warnings);
4692
2/2
✓ Branch 0 taken 469 times.
✓ Branch 1 taken 1855166 times.
1855635 if (tmp == -1LL) reset();
4693 1855635 return tmp;
4694 }
4695
4696 /****************************************************************************
4697 ** Common code for temporal data types with date: DATE, DATETIME, TIMESTAMP
4698 *****************************************************************************/
4699
4700 495065 bool Field_temporal_with_date::get_internal_check_zero(
4701 MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const {
4702
2/2
✓ Branch 0 taken 268 times.
✓ Branch 1 taken 494820 times.
495065 if (get_date_internal(ltime)) /* '0000-00-00' */
4703 {
4704
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 268 times.
268 assert(type() == MYSQL_TYPE_TIMESTAMP);
4705
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 242 times.
268 if (fuzzydate & TIME_NO_ZERO_DATE) return true;
4706 242 set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME);
4707 }
4708 495056 return false;
4709 }
4710
4711 21410 longlong Field_temporal_with_date::val_date_temporal() const {
4712
3/6
✓ Branch 0 taken 21410 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21410 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 21410 times.
21410 ASSERT_COLUMN_MARKED_FOR_READ;
4713 MYSQL_TIME ltime;
4714
3/4
✓ Branch 0 taken 21410 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1583 times.
✓ Branch 3 taken 19827 times.
21410 return get_date_internal(&ltime) ? 0
4715
1/2
✓ Branch 0 taken 19827 times.
✗ Branch 1 not taken.
21410 : TIME_to_longlong_datetime_packed(ltime);
4716 }
4717
4718 longlong Field_temporal_with_date::val_time_temporal() const {
4719 ASSERT_COLUMN_MARKED_FOR_READ;
4720 MYSQL_TIME ltime;
4721 return get_date_internal(&ltime) ? 0 : TIME_to_longlong_time_packed(ltime);
4722 }
4723
4724 70660 longlong Field_temporal_with_date::val_date_temporal_at_utc() const {
4725
3/6
✓ Branch 0 taken 70660 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70660 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 70660 times.
70660 ASSERT_COLUMN_MARKED_FOR_READ;
4726 MYSQL_TIME ltime;
4727
1/2
✓ Branch 0 taken 70660 times.
✗ Branch 1 not taken.
70660 return get_date_internal_at_utc(&ltime)
4728
2/2
✓ Branch 0 taken 927 times.
✓ Branch 1 taken 69733 times.
70660 ? 0
4729
1/2
✓ Branch 0 taken 69733 times.
✗ Branch 1 not taken.
70660 : TIME_to_longlong_datetime_packed(ltime);
4730 }
4731
4732 longlong Field_temporal_with_date::val_time_temporal_at_utc() const {
4733 /*
4734 There are currently no tests covering this method,
4735 as DATETIME seems to always superseed over TIME in comparison.
4736 */
4737 ASSERT_COLUMN_MARKED_FOR_READ;
4738 MYSQL_TIME ltime;
4739 return get_date_internal_at_utc(&ltime) ? 0
4740 : TIME_to_longlong_time_packed(ltime);
4741 }
4742
4743 /**
4744 Convert a number in format YYMMDDhhmmss to string.
4745 Straight coded to avoid problem with slow longlong arithmetic and sprintf.
4746
4747 @param[out] pos pointer to convert to.
4748 @param tmp number with datetime value.
4749 */
4750 46 static inline int my_datetime_number_to_str(char *pos, longlong tmp) {
4751 46 long part1 = (long)(tmp / 1000000LL);
4752 46 long part2 = (long)(tmp - (ulonglong)part1 * 1000000LL);
4753 int part3;
4754 46 pos += MAX_DATETIME_WIDTH; /* Start from the end */
4755 46 *pos-- = 0;
4756 46 *pos-- = (char)('0' + (char)(part2 % 10)); /* Seconds */
4757 46 part2 /= 10;
4758 46 *pos-- = (char)('0' + (char)(part2 % 10));
4759 46 part3 = (int)(part2 / 10);
4760 46 *pos-- = ':';
4761 46 *pos-- = (char)('0' + (char)(part3 % 10)); /* Minutes */
4762 46 part3 /= 10;
4763 46 *pos-- = (char)('0' + (char)(part3 % 10));
4764 46 part3 /= 10;
4765 46 *pos-- = ':';
4766 46 *pos-- = (char)('0' + (char)(part3 % 10)); /* Hours */
4767 46 part3 /= 10;
4768 46 *pos-- = (char)('0' + (char)part3);
4769 46 *pos-- = ' ';
4770 46 *pos-- = (char)('0' + (char)(part1 % 10)); /* Day */
4771 46 part1 /= 10;
4772 46 *pos-- = (char)('0' + (char)(part1 % 10));
4773 46 part1 /= 10;
4774 46 *pos-- = '-';
4775 46 *pos-- = (char)('0' + (char)(part1 % 10)); /* Month */
4776 46 part1 /= 10;
4777 46 *pos-- = (char)('0' + (char)(part1 % 10));
4778 46 part3 = (int)(part1 / 10);
4779 46 *pos-- = '-';
4780 46 *pos-- = (char)('0' + (char)(part3 % 10)); /* Year */
4781 46 part3 /= 10;
4782 46 *pos-- = (char)('0' + (char)(part3 % 10));
4783 46 part3 /= 10;
4784 46 *pos-- = (char)('0' + (char)(part3 % 10));
4785 46 part3 /= 10;
4786 46 *pos = (char)('0' + (char)part3);
4787 46 return MAX_DATETIME_WIDTH;
4788 }
4789
4790 176762 String *Field_temporal_with_date::val_str(String *val_buffer, String *) const {
4791
4/6
✓ Branch 0 taken 176762 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 156034 times.
✓ Branch 3 taken 20728 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 156034 times.
176762 ASSERT_COLUMN_MARKED_FOR_READ;
4792 MYSQL_TIME ltime;
4793
1/2
✓ Branch 0 taken 176762 times.
✗ Branch 1 not taken.
176762 val_buffer->alloc(field_length + 1);
4794 176762 val_buffer->set_charset(&my_charset_numeric);
4795
3/4
✓ Branch 0 taken 176762 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1044 times.
✓ Branch 3 taken 175718 times.
176762 if (get_date_internal(&ltime)) {
4796
1/2
✓ Branch 0 taken 1044 times.
✗ Branch 1 not taken.
1044 val_buffer->set_ascii(my_zero_datetime6, field_length);
4797 1044 return val_buffer;
4798 }
4799
1/2
✓ Branch 0 taken 175718 times.
✗ Branch 1 not taken.
175718 make_datetime((Date_time_format *)nullptr, &ltime, val_buffer, dec);
4800 175718 return val_buffer;
4801 }
4802
4803 1855716 type_conversion_status Field_temporal_with_date::convert_number_to_TIME(
4804 longlong nr, bool unsigned_val, int nanoseconds, MYSQL_TIME *ltime,
4805 int *warnings) {
4806
4/4
✓ Branch 0 taken 1855640 times.
✓ Branch 1 taken 76 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 1855634 times.
1855716 if (nr < 0 || nanoseconds < 0) {
4807 82 reset();
4808 82 *warnings |= MYSQL_TIME_WARN_OUT_OF_RANGE;
4809 82 return TYPE_WARN_OUT_OF_RANGE;
4810 }
4811
4812
2/2
✓ Branch 0 taken 469 times.
✓ Branch 1 taken 1855166 times.
1855634 if (convert_number_to_datetime(nr, unsigned_val, ltime, warnings) == -1LL)
4813 469 return TYPE_ERR_BAD_VALUE;
4814
4815
4/4
✓ Branch 0 taken 695 times.
✓ Branch 1 taken 1854471 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 683 times.
1855166 if (ltime->time_type == MYSQL_TIMESTAMP_DATE && nanoseconds) {
4816 12 *warnings |= MYSQL_TIME_WARN_TRUNCATED;
4817 12 return TYPE_NOTE_TRUNCATED;
4818 }
4819
4820 1855154 ltime->second_part = 0;
4821
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1855152 times.
1855153 if (propagate_datetime_overflow(current_thd, warnings,
4822 1855153 datetime_add_nanoseconds_adjust_frac(
4823 ltime, nanoseconds, warnings,
4824 1855154 (date_flags() & TIME_FRAC_TRUNCATE)))) {
4825 1 reset();
4826 1 return TYPE_WARN_OUT_OF_RANGE;
4827 }
4828 1855152 return TYPE_OK;
4829 }
4830
4831 3039597 type_conversion_status Field_temporal_with_date::store_time(MYSQL_TIME *ltime,
4832 uint8) {
4833
4/6
✓ Branch 0 taken 3039597 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3039576 times.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3039625 times.
3039597 ASSERT_COLUMN_MARKED_FOR_WRITE;
4834 type_conversion_status error;
4835 3039646 int warnings = 0;
4836
4837
3/3
✓ Branch 0 taken 3039384 times.
✓ Branch 1 taken 252 times.
✓ Branch 2 taken 10 times.
3039646 switch (ltime->time_type) // TS-TODO: split into separate methods?
4838 {
4839 3039384 case MYSQL_TIMESTAMP_DATETIME:
4840 case MYSQL_TIMESTAMP_DATETIME_TZ:
4841 case MYSQL_TIMESTAMP_DATE:
4842
4/6
✓ Branch 0 taken 3039381 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3039345 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 329 times.
✓ Branch 5 taken 3039016 times.
3039384 if (check_date(*ltime, non_zero_date(*ltime), date_flags(), &warnings)) {
4843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 329 times.
329 assert(warnings &
4844 (MYSQL_TIME_WARN_OUT_OF_RANGE | MYSQL_TIME_WARN_ZERO_DATE |
4845 MYSQL_TIME_WARN_ZERO_IN_DATE));
4846
4847 329 error = time_warning_to_type_conversion_status(warnings);
4848
1/2
✓ Branch 0 taken 341 times.
✗ Branch 1 not taken.
329 reset();
4849 } else {
4850
1/2
✓ Branch 0 taken 3039016 times.
✗ Branch 1 not taken.
3039016 error = store_internal_adjust_frac(ltime, &warnings);
4851 }
4852 3039357 break;
4853 252 case MYSQL_TIMESTAMP_TIME: {
4854 /* Convert TIME to DATETIME */
4855
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 THD *thd = current_thd;
4856 MYSQL_TIME ltime2;
4857
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 time_to_datetime(thd, ltime, &ltime2);
4858
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 error = store_internal_adjust_frac(&ltime2, &warnings);
4859 252 break;
4860 }
4861 10 case MYSQL_TIMESTAMP_NONE:
4862 case MYSQL_TIMESTAMP_ERROR:
4863 default:
4864 10 warnings |= MYSQL_TIME_WARN_TRUNCATED;
4865
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 reset();
4866 10 error = TYPE_WARN_TRUNCATED;
4867 }
4868
4869
9/12
✓ Branch 0 taken 808 times.
✓ Branch 1 taken 3038811 times.
✓ Branch 2 taken 808 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 808 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 808 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 90 times.
✓ Branch 9 taken 718 times.
✓ Branch 10 taken 90 times.
✓ Branch 11 taken 3039529 times.
3039619 if (warnings && set_warnings(ErrConvString(ltime, decimals()), warnings))
4870 90 return TYPE_ERR_BAD_VALUE;
4871
4872 3039529 return error;
4873 }
4874
4875 98610 bool Field_temporal_with_date::convert_str_to_TIME(const char *str, size_t len,
4876 const CHARSET_INFO *cs,
4877 MYSQL_TIME *ltime,
4878 MYSQL_TIME_STATUS *status) {
4879 295830 return propagate_datetime_overflow(
4880 98610 current_thd, &status->warnings,
4881 197220 str_to_datetime(cs, str, len, ltime, date_flags(), status));
4882 }
4883
4884 8431825 bool Field_temporal_with_date::send_to_protocol(Protocol *protocol) const {
4885
4/6
✓ Branch 0 taken 8431761 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7908397 times.
✓ Branch 3 taken 523364 times.
✓ Branch 4 taken 7908397 times.
✗ Branch 5 not taken.
8431825 if (is_null()) return protocol->store_null();
4886 MYSQL_TIME ltime;
4887
3/4
✓ Branch 0 taken 523475 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2340 times.
✓ Branch 3 taken 521135 times.
523364 if (get_date_internal(&ltime)) {
4888 // Only MYSQL_TYPE_TIMESTAMP can return an error in get_date_internal()
4889
2/4
✓ Branch 0 taken 2340 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2340 times.
2340 assert(type() == MYSQL_TYPE_TIMESTAMP);
4890
1/2
✓ Branch 0 taken 2340 times.
✗ Branch 1 not taken.
2340 set_zero_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
4891 }
4892
1/2
✓ Branch 0 taken 523443 times.
✗ Branch 1 not taken.
523475 return protocol->store_datetime(ltime, dec);
4893 }
4894
4895 3136245 type_conversion_status Field_temporal_with_date::store_internal_adjust_frac(
4896 MYSQL_TIME *ltime, int *warnings) {
4897
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3136259 times.
3136272 if (propagate_datetime_overflow(
4898 3136301 current_thd, warnings,
4899 3136293 my_datetime_adjust_frac(ltime, dec, warnings,
4900 3136245 (date_flags() & TIME_FRAC_TRUNCATE)))) {
4901 13 reset();
4902 13 return time_warning_to_type_conversion_status(*warnings);
4903 } else
4904 3136259 return store_internal(ltime, warnings);
4905 }
4906
4907 /**
4908 Validate date value stored in the field.
4909
4910 Now we check whether date value is zero or has zero in date or not and sets
4911 warning/error message appropriately(depending on the sql_mode).
4912 */
4913 576 type_conversion_status Field_temporal_with_date::validate_stored_val(THD *) {
4914 MYSQL_TIME ltime;
4915 576 type_conversion_status error = TYPE_OK;
4916 576 int warnings = 0;
4917
4918
3/4
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✓ Branch 3 taken 160 times.
576 if (is_real_null()) return error;
4919
4920 160 memset(&ltime, 0, sizeof(MYSQL_TIME));
4921
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 get_date_internal(&ltime);
4922
4/6
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 160 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 158 times.
160 if (check_date(ltime, non_zero_date(ltime), date_flags(), &warnings))
4923 2 error = time_warning_to_type_conversion_status(warnings);
4924
4925
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 158 times.
160 if (warnings) {
4926
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 ltime.time_type = field_type_to_timestamp_type(type());
4927
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 if (set_warnings(ErrConvString(&ltime, dec), warnings))
4928 2 return TYPE_ERR_BAD_VALUE;
4929 }
4930
4931 158 return error;
4932 }
4933
4934 /****************************************************************************
4935 ** Common code for data types with date and time: DATETIME, TIMESTAMP
4936 *****************************************************************************/
4937
4938 4167874 void Field_temporal_with_date_and_time::store_timestamp(const my_timeval *tm) {
4939
3/6
✓ Branch 0 taken 4167874 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4167874 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4167874 times.
4167874 ASSERT_COLUMN_MARKED_FOR_WRITE;
4940
3/4
✓ Branch 0 taken 4167874 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4166126 times.
✓ Branch 3 taken 1748 times.
4167874 if (!my_time_fraction_remainder(tm->m_tv_usec, decimals())) {
4941
1/2
✓ Branch 0 taken 4166126 times.
✗ Branch 1 not taken.
4166126 store_timestamp_internal(tm);
4942 4166126 return;
4943 }
4944 1748 my_timeval tm2 = *tm;
4945
2/4
✓ Branch 0 taken 1748 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1748 times.
✗ Branch 3 not taken.
1748 my_timeval_round(&tm2, decimals());
4946
1/2
✓ Branch 0 taken 1748 times.
✗ Branch 1 not taken.
1748 store_timestamp_internal(&tm2);
4947 }
4948
4949 2107944 bool Field_temporal_with_date_and_time::convert_TIME_to_timestamp(
4950 const MYSQL_TIME *ltime, const Time_zone &tz, my_timeval *tm,
4951 int *warnings) {
4952 /*
4953 No need to do check_date(TIME_NO_ZERO_IN_DATE),
4954 because it has been done earlier in
4955 store_time(), number_to_datetime() or str_to_datetime().
4956 */
4957
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 2107871 times.
2107944 if (datetime_with_no_zero_in_date_to_timeval(ltime, tz, tm, warnings)) {
4958 74 tm->m_tv_sec = tm->m_tv_usec = 0;
4959 74 return true;
4960 }
4961 // Check if the time since epoch fits in TIMESTAMP.
4962
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2107825 times.
2107871 if (tm->m_tv_sec > TYPE_TIMESTAMP_MAX_VALUE) {
4963 46 tm->m_tv_sec = tm->m_tv_usec = 0;
4964 46 *warnings |= MYSQL_TIME_WARN_OUT_OF_RANGE;
4965 }
4966
4967 2107871 return false;
4968 }
4969
4970 1461182 void Field_temporal_with_date_and_time::init_timestamp_flags() {
4971
4/4
✓ Branch 0 taken 365043 times.
✓ Branch 1 taken 1096139 times.
✓ Branch 2 taken 364984 times.
✓ Branch 3 taken 59 times.
1461182 if (auto_flags != NONE && (!(auto_flags & GENERATED_FROM_EXPRESSION))) {
4972 /*
4973 This TIMESTAMP column is hereby quietly assumed to have an insert or
4974 update default function.
4975 */
4976 364984 set_flag(TIMESTAMP_FLAG);
4977
2/2
✓ Branch 0 taken 318041 times.
✓ Branch 1 taken 46943 times.
364984 if (auto_flags & ON_UPDATE_NOW) set_flag(ON_UPDATE_NOW_FLAG);
4978 }
4979 1461182 }
4980
4981 /****************************************************************************
4982 ** Common code for DATETIME(N) and TIMESTAMP(N)
4983 *****************************************************************************/
4984
4985 625 double Field_temporal_with_date_and_timef::val_real() const {
4986
3/6
✓ Branch 0 taken 625 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 625 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 625 times.
625 ASSERT_COLUMN_MARKED_FOR_READ;
4987 MYSQL_TIME ltime;
4988
4/6
✓ Branch 0 taken 625 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 613 times.
✓ Branch 4 taken 613 times.
✗ Branch 5 not taken.
625 return get_date_internal(&ltime) ? 0 : TIME_to_double_datetime(ltime);
4989 }
4990
4991 6579574 longlong Field_temporal_with_date_and_timef::val_int() const {
4992
3/6
✓ Branch 0 taken 6579574 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6579576 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6579576 times.
6579574 ASSERT_COLUMN_MARKED_FOR_READ;
4993 MYSQL_TIME ltime;
4994
1/2
✓ Branch 0 taken 6579576 times.
✗ Branch 1 not taken.
6579574 return get_date_internal(&ltime)
4995
2/2
✓ Branch 0 taken 11518 times.
✓ Branch 1 taken 6568058 times.
6579576 ? 0
4996
2/4
✓ Branch 0 taken 6568058 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6568055 times.
✗ Branch 3 not taken.
6568058 : propagate_datetime_overflow(current_thd, [&](int *w) {
4997 6568055 return TIME_to_ulonglong_datetime_round(ltime, w);
4998 6579573 });
4999 }
5000
5001 293 my_decimal *Field_temporal_with_date_and_timef::val_decimal(
5002 my_decimal *dec_arg) const {
5003
3/6
✓ Branch 0 taken 293 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 293 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 293 times.
293 ASSERT_COLUMN_MARKED_FOR_READ;
5004 MYSQL_TIME ltime;
5005
2/4
✓ Branch 0 taken 293 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 293 times.
293 if (get_date_internal(&ltime)) {
5006 // Only MYSQL_TYPE_TIMESTAMP can return an error in get_date_internal()
5007 assert(type() == MYSQL_TYPE_TIMESTAMP);
5008 set_zero_time(&ltime, MYSQL_TIMESTAMP_DATETIME);
5009 }
5010
1/2
✓ Branch 0 taken 293 times.
✗ Branch 1 not taken.
586 return date2my_decimal(&ltime, dec_arg);
5011 }
5012
5013 /**
5014 TIMESTAMP type columns hold date and time values in the range 1970-01-01
5015 00:00:01 UTC to 2038-01-01 00:00:00 UTC, stored as number of seconds since
5016 the start of the Unix Epoch (1970-01-01 00:00:01 UTC.)
5017
5018 TIMESTAMP columns can be automatically set on row updates to and/or have
5019 CURRENT_TIMESTAMP as default value for inserts.
5020 We use flags Field::auto_flags member to control this behavior.
5021 */
5022 21 Field_timestamp::Field_timestamp(uchar *ptr_arg, uint32, uchar *null_ptr_arg,
5023 uchar null_bit_arg, uchar auto_flags_arg,
5024 21 const char *field_name_arg)
5025 : Field_temporal_with_date_and_time(ptr_arg, null_ptr_arg, null_bit_arg,
5026 21 auto_flags_arg, field_name_arg, 0) {
5027
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 init_timestamp_flags();
5028 /* For 4.0 MYD and 4.0 InnoDB compatibility */
5029 21 set_flag(ZEROFILL_FLAG);
5030 21 set_flag(UNSIGNED_FLAG);
5031 21 }
5032
5033 1 Field_timestamp::Field_timestamp(bool is_nullable_arg,
5034 1 const char *field_name_arg)
5035 : Field_temporal_with_date_and_time(
5036 nullptr, is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
5037
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 field_name_arg, 0) {
5038
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 init_timestamp_flags();
5039 /* For 4.0 MYD and 4.0 InnoDB compatibility */
5040 1 set_flag(ZEROFILL_FLAG);
5041 1 set_flag(UNSIGNED_FLAG);
5042 1 }
5043
5044 2 my_time_flags_t Field_timestamp::date_flags(const THD *thd) const {
5045 /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
5046 2 my_time_flags_t date_flags = TIME_NO_ZERO_IN_DATE;
5047
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (thd->variables.sql_mode & MODE_NO_ZERO_DATE)
5048 2 date_flags |= TIME_NO_ZERO_DATE;
5049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL)
5050 date_flags |= TIME_FRAC_TRUNCATE;
5051
5052 2 return date_flags;
5053 }
5054
5055 1 type_conversion_status Field_timestamp::store_internal(const MYSQL_TIME *ltime,
5056 int *warnings) {
5057
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 THD *thd = current_thd;
5058 my_timeval tm;
5059
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 convert_TIME_to_timestamp(ltime, *thd->time_zone(), &tm, warnings);
5060 const type_conversion_status error =
5061 1 time_warning_to_type_conversion_status(*warnings);
5062
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 store_timestamp_internal(&tm);
5063 1 return error;
5064 }
5065
5066 5 bool Field_timestamp::get_date_internal(MYSQL_TIME *ltime) const {
5067 5 THD *thd = current_thd;
5068 5 return get_date_internal_at(thd->time_zone(), ltime);
5069 }
5070
5071 bool Field_timestamp::get_date_internal_at_utc(MYSQL_TIME *ltime) const {
5072 return get_date_internal_at(my_tz_UTC, ltime);
5073 }
5074
5075 5 bool Field_timestamp::get_date_internal_at(const Time_zone *tz,
5076 MYSQL_TIME *ltime) const {
5077
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
5 ASSERT_COLUMN_MARKED_FOR_READ;
5078
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 my_time_t temp = (table != nullptr && table->s->db_low_byte_first)
5079
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
10 ? uint4korr(ptr)
5080 : ulongget(ptr);
5081
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 if (temp == 0) return true;
5082
5083 4 tz->gmt_sec_to_TIME(ltime, temp);
5084 4 return false;
5085 }
5086
5087 /**
5088 Get TIMESTAMP field value as seconds since begging of Unix Epoch
5089 */
5090 16 bool Field_timestamp::get_timestamp(my_timeval *tm, int *) const {
5091
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (is_null()) return true;
5092 16 tm->m_tv_usec = 0;
5093
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 if (table && table->s->db_low_byte_first) {
5094 16 tm->m_tv_sec = sint4korr(ptr);
5095 16 return false;
5096 }
5097 tm->m_tv_sec = longget(ptr);
5098 return false;
5099 }
5100
5101 6 void Field_timestamp::store_timestamp_internal(const my_timeval *tm) {
5102
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (table && table->s->db_low_byte_first)
5103 6 int4store(ptr, tm->m_tv_sec);
5104 else
5105 longstore(ptr, (uint32)tm->m_tv_sec);
5106 6 }
5107
5108 type_conversion_status Field_timestamp::store_packed(longlong nr) {
5109 /* Make sure the stored value was previously properly rounded or truncated */
5110 assert((my_packed_time_get_frac_part(nr) %
5111 (int)log_10_int[DATETIME_MAX_DECIMALS - decimals()]) == 0);
5112 MYSQL_TIME ltime;
5113 TIME_from_longlong_datetime_packed(&ltime, nr);
5114 return Field_timestamp::store_time(&ltime, 0);
5115 }
5116
5117 longlong Field_timestamp::val_int() const {
5118 ASSERT_COLUMN_MARKED_FOR_READ;
5119 MYSQL_TIME ltime;
5120 return get_date_internal(&ltime) ? 0 : TIME_to_ulonglong_datetime(ltime);
5121 }
5122
5123 2 bool Field_timestamp::get_date(MYSQL_TIME *ltime,
5124 my_time_flags_t fuzzydate) const {
5125 /* Don't do check_fuzzy_date() as month and year are never 0 for timestamp */
5126 2 return get_internal_check_zero(ltime, fuzzydate);
5127 }
5128
5129 int Field_timestamp::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
5130 int32 a, b;
5131 if (table && table->s->db_low_byte_first) {
5132 a = sint4korr(a_ptr);
5133 b = sint4korr(b_ptr);
5134 } else {
5135 a = longget(a_ptr);
5136 b = longget(b_ptr);
5137 }
5138 return ((uint32)a < (uint32)b) ? -1 : ((uint32)a > (uint32)b) ? 1 : 0;
5139 }
5140
5141 2 size_t Field_timestamp::make_sort_key(uchar *to,
5142 size_t length [[maybe_unused]]) const {
5143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert(length == 4);
5144 #ifdef WORDS_BIGENDIAN
5145 if (!table || !table->s->db_low_byte_first) {
5146 to[0] = ptr[0];
5147 to[1] = ptr[1];
5148 to[2] = ptr[2];
5149 to[3] = ptr[3];
5150 } else
5151 #endif
5152 {
5153 2 to[0] = ptr[3];
5154 2 to[1] = ptr[2];
5155 2 to[2] = ptr[1];
5156 2 to[3] = ptr[0];
5157 }
5158 2 return 4;
5159 }
5160
5161 4 void Field_timestamp::sql_type(String &res) const {
5162 4 res.set_ascii(STRING_WITH_LEN("timestamp"));
5163 4 }
5164
5165 type_conversion_status Field_timestamp::validate_stored_val(THD *thd) {
5166 /*
5167 While deprecating "TIMESTAMP with implicit DEFAULT value", we can
5168 remove this function implementation and depend directly on
5169 "Field_temporal_with_date::validate_stored_val"
5170 */
5171 if (!thd->variables.explicit_defaults_for_timestamp) return TYPE_OK;
5172
5173 return (Field_temporal_with_date::validate_stored_val(thd));
5174 }
5175
5176 /****************************************************************************
5177 ** timestamp(N) type
5178 ** In string context: YYYY-MM-DD HH:MM:SS.FFFFFF
5179 ** In number context: YYYYMMDDHHMMSS.FFFFFF
5180 ** Stored as a 7 byte value
5181 ****************************************************************************/
5182 1461160 Field_timestampf::Field_timestampf(uchar *ptr_arg, uchar *null_ptr_arg,
5183 uchar null_bit_arg, uchar auto_flags_arg,
5184 1461160 const char *field_name_arg, uint8 dec_arg)
5185 : Field_temporal_with_date_and_timef(ptr_arg, null_ptr_arg, null_bit_arg,
5186 auto_flags_arg, field_name_arg,
5187 1461160 dec_arg) {
5188
1/2
✓ Branch 0 taken 1461160 times.
✗ Branch 1 not taken.
1461160 init_timestamp_flags();
5189 1461160 }
5190
5191 62 Field_timestampf::Field_timestampf(bool is_nullable_arg,
5192 62 const char *field_name_arg, uint8 dec_arg)
5193 : Field_temporal_with_date_and_timef(
5194 nullptr, is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
5195
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 51 times.
62 field_name_arg, dec_arg) {
5196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
62 if (auto_flags & ON_UPDATE_NOW) set_flag(ON_UPDATE_NOW_FLAG);
5197 62 }
5198
5199 4216823 my_time_flags_t Field_timestampf::date_flags(const THD *thd) const {
5200 /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
5201 4216823 my_time_flags_t date_flags = TIME_NO_ZERO_IN_DATE;
5202
2/2
✓ Branch 0 taken 485414 times.
✓ Branch 1 taken 3731409 times.
4216823 if (thd->variables.sql_mode & MODE_NO_ZERO_DATE)
5203 485414 date_flags |= TIME_NO_ZERO_DATE;
5204
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 4216697 times.
4216823 if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL)
5205 126 date_flags |= TIME_FRAC_TRUNCATE;
5206
5207 4216823 return date_flags;
5208 }
5209
5210 6275505 void Field_timestampf::store_timestamp_internal(const my_timeval *tm) {
5211 6275505 my_timestamp_to_binary(tm, ptr, dec);
5212 6275504 }
5213
5214 2107943 type_conversion_status Field_timestampf::store_internal(const MYSQL_TIME *ltime,
5215 int *warnings) {
5216
1/2
✓ Branch 0 taken 2107944 times.
✗ Branch 1 not taken.
2107943 THD *thd = current_thd;
5217 my_timeval tm;
5218
1/2
✓ Branch 0 taken 2107944 times.
✗ Branch 1 not taken.
2107944 convert_TIME_to_timestamp(ltime, *thd->time_zone(), &tm, warnings);
5219 const type_conversion_status error =
5220 2107944 time_warning_to_type_conversion_status(*warnings);
5221
1/2
✓ Branch 0 taken 2107943 times.
✗ Branch 1 not taken.
2107944 store_timestamp_internal(&tm);
5222 2107943 return error;
5223 }
5224
5225 39 type_conversion_status Field_timestampf::store_packed(longlong nr) {
5226 MYSQL_TIME ltime;
5227
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 TIME_from_longlong_datetime_packed(&ltime, nr);
5228
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
78 return Field_timestampf::store_time(&ltime, dec);
5229 }
5230
5231 58660 bool Field_timestampf::get_date(MYSQL_TIME *ltime,
5232 my_time_flags_t fuzzydate) const {
5233 /* Don't do check_fuzzy_date() as month and year are never 0 for timestamp */
5234 58660 return get_internal_check_zero(ltime, fuzzydate);
5235 }
5236
5237 347720 void Field_timestampf::sql_type(String &res) const {
5238
2/2
✓ Branch 0 taken 279172 times.
✓ Branch 1 taken 68548 times.
347720 if (dec == 0) {
5239 279172 res.set_ascii(STRING_WITH_LEN("timestamp"));
5240 279172 return;
5241 }
5242 68548 const CHARSET_INFO *cs = res.charset();
5243 68548 res.length(cs->cset->snprintf(cs, res.ptr(), res.alloced_length(),
5244 68548 "timestamp(%d)", dec));
5245 }
5246
5247 6914103 bool Field_timestampf::get_date_internal(MYSQL_TIME *ltime) const {
5248 6914103 THD *thd = current_thd;
5249 6914106 return get_date_internal_at(thd->time_zone(), ltime);
5250 }
5251
5252 16889 bool Field_timestampf::get_date_internal_at_utc(MYSQL_TIME *ltime) const {
5253 16889 return get_date_internal_at(my_tz_UTC, ltime);
5254 }
5255
5256 109256 bool Field_timestampf::get_timestamp(my_timeval *tm, int *) const {
5257 109256 THD *thd = current_thd;
5258 109256 thd->time_zone_used = true;
5259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 109256 times.
109256 assert(!is_null());
5260 109256 my_timestamp_from_binary(tm, ptr, dec);
5261 109256 return false;
5262 }
5263
5264 6930993 bool Field_timestampf::get_date_internal_at(const Time_zone *tz,
5265 MYSQL_TIME *ltime) const {
5266 my_timeval tm;
5267
1/2
✓ Branch 0 taken 6930992 times.
✗ Branch 1 not taken.
6930993 my_timestamp_from_binary(&tm, ptr, dec);
5268
2/2
✓ Branch 0 taken 17724 times.
✓ Branch 1 taken 6913268 times.
6930992 if (tm.m_tv_sec == 0) return true;
5269
1/2
✓ Branch 0 taken 6913270 times.
✗ Branch 1 not taken.
6913268 tz->gmt_sec_to_TIME(ltime, tm);
5270 6913270 return false;
5271 }
5272
5273 395 type_conversion_status Field_timestampf::validate_stored_val(THD *thd) {
5274 /*
5275 While deprecating "TIMESTAMP with implicit DEFAULT value", we can
5276 remove this function implementation and depend directly on
5277 "Field_temporal_with_date::validate_stored_val"
5278 */
5279
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 384 times.
395 if (!thd->variables.explicit_defaults_for_timestamp) return TYPE_OK;
5280
5281 384 return (Field_temporal_with_date::validate_stored_val(thd));
5282 }
5283
5284 /****************************************************************************
5285 ** TIME and TIME(N) common methods
5286 ****************************************************************************/
5287
5288 15343 bool Field_time_common::convert_str_to_TIME(const char *str, size_t len,
5289 const CHARSET_INFO *cs,
5290 MYSQL_TIME *ltime,
5291 MYSQL_TIME_STATUS *status) {
5292 15343 return str_to_time(cs, str, len, ltime, date_flags(), status);
5293 }
5294
5295 1248 type_conversion_status Field_time_common::convert_number_to_TIME(
5296 longlong nr, bool unsigned_val, int nanoseconds, MYSQL_TIME *ltime,
5297 int *warnings) {
5298
4/4
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1233 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 7 times.
1248 if (unsigned_val && nr < 0) {
5299 8 *warnings |= MYSQL_TIME_WARN_OUT_OF_RANGE;
5300 8 set_max_time(ltime, false);
5301 8 store_internal(ltime, warnings);
5302 8 return TYPE_WARN_OUT_OF_RANGE;
5303 }
5304
2/2
✓ Branch 0 taken 169 times.
✓ Branch 1 taken 1071 times.
1240 if (number_to_time(nr, ltime, warnings)) {
5305 169 store_internal(ltime, warnings);
5306 169 return TYPE_WARN_OUT_OF_RANGE;
5307 }
5308 /*
5309 Both number_to_time() call and negative nanoseconds value
5310 affect ltime->neg, hence "|=" to combine them:
5311 */
5312
2/2
✓ Branch 0 taken 121 times.
✓ Branch 1 taken 950 times.
1071 if ((ltime->neg |= (nanoseconds < 0))) nanoseconds = -nanoseconds;
5313 1071 ltime->second_part = 0;
5314
5315 2142 bool error = time_add_nanoseconds_adjust_frac(
5316 1071 ltime, nanoseconds, warnings, (date_flags() & TIME_FRAC_TRUNCATE));
5317
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1071 times.
1071 return error ? time_warning_to_type_conversion_status(*warnings) : TYPE_OK;
5318 }
5319
5320 7919 type_conversion_status Field_time_common::store_time(MYSQL_TIME *ltime, uint8) {
5321 /* Check if seconds or minutes are out of range */
5322
2/4
✓ Branch 0 taken 7919 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7919 times.
7919 if (ltime->second >= 60 || ltime->minute >= 60) {
5323 if (set_warnings(ErrConvString(ltime, decimals()),
5324 MYSQL_TIME_WARN_OUT_OF_RANGE))
5325 return TYPE_ERR_BAD_VALUE;
5326 reset();
5327 return TYPE_WARN_OUT_OF_RANGE;
5328 }
5329 7919 int warnings = 0;
5330
1/2
✓ Branch 0 taken 7919 times.
✗ Branch 1 not taken.
7919 return store_internal_adjust_frac(ltime, &warnings);
5331 }
5332
5333 23621 type_conversion_status Field_time_common::store_internal_adjust_frac(
5334 MYSQL_TIME *ltime, int *warnings) {
5335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23621 times.
23621 if (my_time_adjust_frac(ltime, dec, (date_flags() & TIME_FRAC_TRUNCATE)))
5336 return TYPE_WARN_OUT_OF_RANGE;
5337
5338 23621 return store_internal(ltime, warnings);
5339 }
5340
5341 6653 String *Field_time_common::val_str(String *val_buffer, String *) const {
5342
5/6
✓ Branch 0 taken 6651 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 6481 times.
✓ Branch 3 taken 170 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6481 times.
6653 ASSERT_COLUMN_MARKED_FOR_READ;
5343 MYSQL_TIME ltime;
5344
1/2
✓ Branch 0 taken 6653 times.
✗ Branch 1 not taken.
6653 val_buffer->alloc(MAX_DATE_STRING_REP_LENGTH);
5345 6653 val_buffer->set_charset(&my_charset_numeric);
5346
2/4
✓ Branch 0 taken 6653 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6653 times.
6653 if (get_time(&ltime)) {
5347 assert(0);
5348 set_zero_time(&ltime, MYSQL_TIMESTAMP_TIME);
5349 }
5350
1/2
✓ Branch 0 taken 6653 times.
✗ Branch 1 not taken.
6653 make_time((Date_time_format *)nullptr, &ltime, val_buffer, dec);
5351 6653 return val_buffer;
5352 }
5353
5354 /**
5355 For a column for TIME type, get_date() takes the time
5356 value of the field, adds current date to it and returns
5357 the result as a DATETIME value.
5358 */
5359
5360 3401 bool Field_time_common::get_date(MYSQL_TIME *ltime, my_time_flags_t) const {
5361
5/6
✓ Branch 0 taken 3400 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3399 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3399 times.
3401 ASSERT_COLUMN_MARKED_FOR_READ;
5362 MYSQL_TIME tm;
5363
2/4
✓ Branch 0 taken 3401 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3401 times.
3401 if (get_time(&tm)) {
5364 assert(0);
5365 set_zero_time(ltime, MYSQL_TIMESTAMP_TIME);
5366 }
5367
2/4
✓ Branch 0 taken 3401 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3401 times.
✗ Branch 3 not taken.
3401 time_to_datetime(current_thd, &tm, ltime);
5368 3401 return false;
5369 }
5370
5371 250 longlong Field_time_common::val_date_temporal() const {
5372
3/6
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 250 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 250 times.
250 ASSERT_COLUMN_MARKED_FOR_READ;
5373 MYSQL_TIME time, datetime;
5374
2/4
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 250 times.
250 if (get_time(&time)) {
5375 assert(0); // Field_time*::get_time should not fail
5376 return 0;
5377 }
5378
2/4
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 250 times.
✗ Branch 3 not taken.
250 time_to_datetime(current_thd, &time, &datetime);
5379
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 return TIME_to_longlong_datetime_packed(datetime);
5380 }
5381
5382 19051 bool Field_time_common::send_to_protocol(Protocol *protocol) const {
5383
4/6
✓ Branch 0 taken 19051 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 516 times.
✓ Branch 3 taken 18535 times.
✓ Branch 4 taken 516 times.
✗ Branch 5 not taken.
19051 if (is_null()) return protocol->store_null();
5384 MYSQL_TIME ltime;
5385
2/4
✓ Branch 0 taken 18535 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18535 times.
18535 if (get_time(&ltime)) {
5386 assert(0);
5387 set_zero_time(&ltime, MYSQL_TIMESTAMP_TIME);
5388 }
5389
1/2
✓ Branch 0 taken 18535 times.
✗ Branch 1 not taken.
18535 return protocol->store_time(ltime, dec);
5390 }
5391
5392 40035 my_time_flags_t Field_time_common::date_flags(const THD *thd) const {
5393 40035 my_time_flags_t date_flags = 0;
5394
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 39836 times.
40035 if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL)
5395 199 date_flags = TIME_FRAC_TRUNCATE;
5396
5397 40035 return date_flags;
5398 }
5399
5400 /****************************************************************************
5401 ** time type
5402 ** In string context: HH:MM:SS
5403 ** In number context: HHMMSS
5404 ** Stored as a 3 byte unsigned int
5405 ****************************************************************************/
5406
5407 1 type_conversion_status Field_time::store_internal(const MYSQL_TIME *ltime,
5408 int *) {
5409
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 long tmp = ((ltime->month ? 0 : ltime->day * 24L) + ltime->hour) * 10000L +
5410 1 (ltime->minute * 100 + ltime->second);
5411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ltime->neg) tmp = -tmp;
5412 1 int3store(ptr, tmp);
5413 1 return TYPE_OK;
5414 }
5415
5416 type_conversion_status Field_time::store_packed(longlong nr) {
5417 MYSQL_TIME ltime;
5418 TIME_from_longlong_time_packed(&ltime, nr);
5419 return Field_time::store_time(&ltime, 0);
5420 }
5421
5422 longlong Field_time::val_time_temporal() const {
5423 ASSERT_COLUMN_MARKED_FOR_READ;
5424 MYSQL_TIME ltime;
5425 return get_time(&ltime) ? 0 : TIME_to_longlong_time_packed(ltime);
5426 }
5427
5428 longlong Field_time::val_int() const {
5429 ASSERT_COLUMN_MARKED_FOR_READ;
5430 return (longlong)sint3korr(ptr);
5431 }
5432
5433 129 bool Field_time::get_time(MYSQL_TIME *ltime) const {
5434 129 long tmp = (long)sint3korr(ptr);
5435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 129 times.
129 if ((ltime->neg = tmp < 0)) tmp = -tmp;
5436 129 ltime->year = ltime->month = ltime->day = 0;
5437 129 TIME_set_hhmmss(ltime, tmp);
5438 129 ltime->second_part = 0;
5439 129 ltime->time_type = MYSQL_TIMESTAMP_TIME;
5440 129 return false;
5441 }
5442
5443 int Field_time::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
5444 int32 a, b;
5445 a = sint3korr(a_ptr);
5446 b = sint3korr(b_ptr);
5447 return (a < b) ? -1 : (a > b) ? 1 : 0;
5448 }
5449
5450 2 size_t Field_time::make_sort_key(uchar *to,
5451 size_t length [[maybe_unused]]) const {
5452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert(length == 3);
5453 2 to[0] = (uchar)(ptr[2] ^ 128);
5454 2 to[1] = ptr[1];
5455 2 to[2] = ptr[0];
5456 2 return 3;
5457 }
5458
5459 65 void Field_time::sql_type(String &res) const {
5460 65 res.set_ascii(STRING_WITH_LEN("time"));
5461 65 }
5462
5463 /****************************************************************************
5464 ** time type with fsp
5465 ** In string context: HH:MM:SS.FFFFFF
5466 ** In number context: HHMMSS.FFFFFF
5467 ****************************************************************************/
5468
5469 117 longlong Field_timef::val_int() const {
5470
4/6
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 111 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 111 times.
117 ASSERT_COLUMN_MARKED_FOR_READ;
5471 MYSQL_TIME ltime;
5472
2/4
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 117 times.
117 if (get_time(&ltime)) {
5473 assert(0);
5474 set_zero_time(&ltime, MYSQL_TIMESTAMP_TIME);
5475 }
5476
1/2
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
117 longlong tmp = (longlong)TIME_to_ulonglong_time_round(ltime);
5477
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 88 times.
117 return ltime.neg ? -tmp : tmp;
5478 }
5479
5480 181 my_decimal *Field_timef::val_decimal(my_decimal *decimal_value) const {
5481
4/6
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 180 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 180 times.
181 ASSERT_COLUMN_MARKED_FOR_READ;
5482 MYSQL_TIME ltime;
5483
2/4
✓ Branch 0 taken 181 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 181 times.
181 if (get_time(&ltime)) {
5484 assert(0);
5485 set_zero_time(&ltime, MYSQL_TIMESTAMP_TIME);
5486 }
5487
1/2
✓ Branch 0 taken 181 times.
✗ Branch 1 not taken.
362 return time2my_decimal(&ltime, decimal_value);
5488 }
5489
5490 267 double Field_timef::val_real() const {
5491
4/6
✓ Branch 0 taken 255 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 255 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 255 times.
267 ASSERT_COLUMN_MARKED_FOR_READ;
5492 MYSQL_TIME ltime;
5493
2/4
✓ Branch 0 taken 267 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 267 times.
267 if (get_time(&ltime)) {
5494 assert(0);
5495 return 0;
5496 }
5497
1/2
✓ Branch 0 taken 267 times.
✗ Branch 1 not taken.
267 double tmp = TIME_to_double_time(ltime);
5498
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 246 times.
267 return ltime.neg ? -tmp : tmp;
5499 }
5500
5501 36970 void Field_timef::sql_type(String &res) const {
5502
2/2
✓ Branch 0 taken 33946 times.
✓ Branch 1 taken 3024 times.
36970 if (dec == 0) {
5503 33946 res.set_ascii(STRING_WITH_LEN("time"));
5504 33946 return;
5505 }
5506 3024 const CHARSET_INFO *cs = res.charset();
5507 3024 res.length(
5508 3024 cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), "time(%d)", dec));
5509 }
5510
5511 91856 type_conversion_status Field_timef::reset() { return store_packed(0); }
5512
5513 116378 type_conversion_status Field_timef::store_packed(longlong nr) {
5514 116378 my_time_packed_to_binary(nr, ptr, dec);
5515 116378 return TYPE_OK;
5516 }
5517
5518 61559 longlong Field_timef::val_time_temporal() const {
5519
5/6
✓ Branch 0 taken 61531 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 61353 times.
✓ Branch 3 taken 178 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 61353 times.
61559 ASSERT_COLUMN_MARKED_FOR_READ;
5520 61559 return my_time_packed_from_binary(ptr, dec);
5521 }
5522
5523 24480 type_conversion_status Field_timef::store_internal(const MYSQL_TIME *ltime,
5524 int *warnings) {
5525 /*
5526 If time zone displacement information is present in "ltime"
5527 - adjust the value to UTC based on the time zone
5528 - convert to the local time zone
5529 */
5530 MYSQL_TIME temp_time;
5531 const MYSQL_TIME *time;
5532
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 24479 times.
24480 if (ltime->time_type == MYSQL_TIMESTAMP_DATETIME_TZ) {
5533 1 temp_time = *ltime;
5534 1 time = &temp_time;
5535
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 if (convert_time_zone_displacement(current_thd->time_zone(), &temp_time))
5536 return TYPE_ERR_BAD_VALUE;
5537 } else {
5538 24479 time = ltime;
5539 }
5540
2/4
✓ Branch 0 taken 24480 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24480 times.
✗ Branch 3 not taken.
24480 type_conversion_status rc = store_packed(TIME_to_longlong_time_packed(*time));
5541
5/6
✓ Branch 0 taken 24480 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1525 times.
✓ Branch 3 taken 22955 times.
✓ Branch 4 taken 1525 times.
✓ Branch 5 taken 22955 times.
24480 if (rc == TYPE_OK && non_zero_date(*ltime)) {
5542 /*
5543 The DATE part got lost; we warn, like in Field_newdate::store_internal,
5544 and trigger some code in get_mm_leaf()
5545 (see err==TYPE_NOTE_TIME_TRUNCATED there).
5546 */
5547 1525 *warnings |= MYSQL_TIME_NOTE_TRUNCATED;
5548 1525 rc = TYPE_NOTE_TIME_TRUNCATED;
5549 }
5550 24480 return rc;
5551 }
5552
5553 38804 bool Field_timef::get_time(MYSQL_TIME *ltime) const {
5554 38804 longlong tmp = val_time_temporal();
5555 38804 TIME_from_longlong_time_packed(ltime, tmp);
5556 38804 return false;
5557 }
5558
5559 /****************************************************************************
5560 ** year type
5561 ** Save in a byte the year 0, 1901->2155
5562 ****************************************************************************/
5563
5564 5791 type_conversion_status Field_year::store(const char *from, size_t len,
5565 const CHARSET_INFO *cs) {
5566
4/6
✓ Branch 0 taken 5791 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5688 times.
✓ Branch 3 taken 103 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5688 times.
5791 ASSERT_COLUMN_MARKED_FOR_WRITE;
5567 const char *end;
5568 int conv_error;
5569 5791 type_conversion_status ret = TYPE_OK;
5570
1/2
✓ Branch 0 taken 5791 times.
✗ Branch 1 not taken.
5791 longlong nr = cs->cset->strntoull10rnd(cs, from, len, 0, &end, &conv_error);
5571
5572
8/8
✓ Branch 0 taken 5741 times.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 3984 times.
✓ Branch 3 taken 1757 times.
✓ Branch 4 taken 3882 times.
✓ Branch 5 taken 102 times.
✓ Branch 6 taken 5587 times.
✓ Branch 7 taken 52 times.
5791 if (nr < 0 || (nr >= 100 && nr < MIN_YEAR) || nr > MAX_YEAR ||
5573
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5587 times.
5587 conv_error == MY_ERRNO_ERANGE) {
5574 204 *ptr = 0;
5575
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
5576 204 return TYPE_WARN_OUT_OF_RANGE;
5577 }
5578
5579
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 5517 times.
5587 if (conv_error) ret = TYPE_ERR_BAD_VALUE;
5580
5581
3/4
✓ Branch 0 taken 5587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4597 times.
✓ Branch 3 taken 990 times.
5587 if (current_thd->check_for_truncated_fields)
5582
1/2
✓ Branch 0 taken 4597 times.
✗ Branch 1 not taken.
4597 ret = check_int(cs, from, len, end, conv_error);
5583
5584
2/2
✓ Branch 0 taken 635 times.
✓ Branch 1 taken 4952 times.
5587 if (ret != TYPE_OK) {
5585
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 565 times.
635 if (ret == TYPE_ERR_BAD_VALUE) /* empty or incorrect string */
5586 {
5587 70 *ptr = 0; // Invalid date
5588 70 return ret;
5589 }
5590 565 ret = TYPE_WARN_OUT_OF_RANGE;
5591 }
5592
5593
4/4
✓ Branch 0 taken 812 times.
✓ Branch 1 taken 4705 times.
✓ Branch 2 taken 81 times.
✓ Branch 3 taken 731 times.
5517 if (nr != 0 || len != 4) {
5594
2/2
✓ Branch 0 taken 737 times.
✓ Branch 1 taken 4049 times.
4786 if (nr < YY_PART_YEAR)
5595 737 nr += 100; // 2000 - 2069
5596
2/2
✓ Branch 0 taken 3830 times.
✓ Branch 1 taken 219 times.
4049 else if (nr > 1900)
5597 3830 nr -= 1900;
5598 }
5599 5517 *ptr = (char)(uchar)nr;
5600 5517 return ret;
5601 }
5602
5603 302 type_conversion_status Field_year::store(double nr) {
5604
4/4
✓ Branch 0 taken 278 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 206 times.
302 if (nr < 0.0 || nr > MAX_YEAR) {
5605 96 Field_year::store(-1LL, false);
5606 96 return TYPE_WARN_OUT_OF_RANGE;
5607 }
5608 206 return Field_year::store(static_cast<longlong>(nr), false);
5609 }
5610
5611 56 type_conversion_status Field_year::store_time(MYSQL_TIME *ltime, uint8) {
5612
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 45 times.
56 if (ltime->time_type != MYSQL_TIMESTAMP_DATETIME &&
5613
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8 times.
11 ltime->time_type != MYSQL_TIMESTAMP_DATE) {
5614 /* Convert time to datetime, then store year of the result */
5615
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 THD *thd = current_thd;
5616 MYSQL_TIME ltime2;
5617
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 time_to_datetime(thd, ltime, &ltime2);
5618
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 return store(ltime2.year, false);
5619 }
5620 53 return store(ltime->year, false);
5621 }
5622
5623 5899 type_conversion_status Field_year::store(longlong nr, bool) {
5624
4/6
✓ Branch 0 taken 5899 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5868 times.
✓ Branch 3 taken 31 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5868 times.
5899 ASSERT_COLUMN_MARKED_FOR_WRITE;
5625
8/8
✓ Branch 0 taken 5769 times.
✓ Branch 1 taken 130 times.
✓ Branch 2 taken 4746 times.
✓ Branch 3 taken 1023 times.
✓ Branch 4 taken 4572 times.
✓ Branch 5 taken 174 times.
✓ Branch 6 taken 138 times.
✓ Branch 7 taken 5457 times.
5899 if (nr < 0 || (nr >= 100 && nr < MIN_YEAR) || nr > MAX_YEAR) {
5626 442 *ptr = 0;
5627 442 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
5628 442 return TYPE_WARN_OUT_OF_RANGE;
5629 }
5630
2/2
✓ Branch 0 taken 5258 times.
✓ Branch 1 taken 199 times.
5457 if (nr != 0) // 0000 -> 0
5631 {
5632
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 4622 times.
5258 if (nr < YY_PART_YEAR)
5633 636 nr += 100; // 2000 - 2069
5634
2/2
✓ Branch 0 taken 4434 times.
✓ Branch 1 taken 188 times.
4622 else if (nr > 1900)
5635 4434 nr -= 1900;
5636 }
5637 5457 *ptr = (char)(uchar)nr;
5638 5457 return TYPE_OK;
5639 }
5640
5641 15958 bool Field_year::send_to_protocol(Protocol *protocol) const {
5642
3/6
✓ Branch 0 taken 15958 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15958 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15958 times.
15958 ASSERT_COLUMN_MARKED_FOR_READ;
5643
2/2
✓ Branch 0 taken 565 times.
✓ Branch 1 taken 15393 times.
15958 if (is_null()) return protocol->store_null();
5644 // YEAR is always ZEROFILL. Always zero-pad values up to 4 digits.
5645
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15393 times.
15393 assert(zerofill);
5646 15393 ulonglong tmp = Field_year::val_int();
5647 15393 return protocol->store_short(tmp, field_length);
5648 }
5649
5650 925 double Field_year::val_real() const { return (double)Field_year::val_int(); }
5651
5652 39065 longlong Field_year::val_int() const {
5653
4/6
✓ Branch 0 taken 39065 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38931 times.
✓ Branch 3 taken 134 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 38931 times.
39065 ASSERT_COLUMN_MARKED_FOR_READ;
5654
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39065 times.
39065 assert(field_length == 4);
5655 39065 int tmp = (int)ptr[0];
5656
2/2
✓ Branch 0 taken 35912 times.
✓ Branch 1 taken 3153 times.
39065 if (tmp != 0) tmp += 1900;
5657 39065 return (longlong)tmp;
5658 }
5659
5660 3502 String *Field_year::val_str(String *val_buffer, String *) const {
5661
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3502 times.
3502 assert(field_length == 4);
5662 3502 val_buffer->length(0);
5663 3502 const longlong year = val_int();
5664 // YEAR is always ZEROFILL. Always zero-pad values up to 4 digits.
5665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3502 times.
3502 assert(zerofill);
5666
2/2
✓ Branch 0 taken 392 times.
✓ Branch 1 taken 3110 times.
3502 if (year == 0)
5667 392 val_buffer->fill(field_length, '0');
5668 else // If year != 0, year is always 4 digits
5669 3110 val_buffer->append_longlong(year);
5670 3502 val_buffer->set_charset(&my_charset_numeric);
5671 3502 return val_buffer;
5672 }
5673
5674 3734 void Field_year::sql_type(String &res) const {
5675 3734 res.length(0);
5676 3734 res.append(STRING_WITH_LEN("year"));
5677 3734 }
5678
5679 /****************************************************************************
5680 ** The new date type
5681 ** Stored as 3 bytes
5682 ** In number context: YYYYMMDD
5683 ****************************************************************************/
5684
5685 424187 my_time_flags_t Field_newdate::date_flags(const THD *thd) const {
5686 424187 my_time_flags_t date_flags = TIME_FUZZY_DATE;
5687
2/2
✓ Branch 0 taken 375159 times.
✓ Branch 1 taken 49028 times.
424187 if (thd->variables.sql_mode & MODE_NO_ZERO_DATE)
5688 375159 date_flags |= TIME_NO_ZERO_DATE;
5689
2/2
✓ Branch 0 taken 375405 times.
✓ Branch 1 taken 48782 times.
424187 if (thd->variables.sql_mode & MODE_NO_ZERO_IN_DATE)
5690 375405 date_flags |= TIME_NO_ZERO_IN_DATE;
5691
2/2
✓ Branch 0 taken 5703 times.
✓ Branch 1 taken 418484 times.
424187 if (thd->variables.sql_mode & MODE_INVALID_DATES)
5692 5703 date_flags |= TIME_INVALID_DATES;
5693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 424187 times.
424187 if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL)
5694 date_flags |= TIME_FRAC_TRUNCATE;
5695
5696 424187 return date_flags;
5697 }
5698
5699 211567 type_conversion_status Field_newdate::store_internal(const MYSQL_TIME *ltime,
5700 int *warnings) {
5701 /*
5702 If time zone displacement information is present in "ltime"
5703 - adjust the value to UTC based on the time zone
5704 - convert to the local time zone
5705 */
5706 MYSQL_TIME temp_time;
5707 const MYSQL_TIME *time;
5708
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 211566 times.
211567 if (ltime->time_type == MYSQL_TIMESTAMP_DATETIME_TZ) {
5709 1 temp_time = *ltime;
5710 1 time = &temp_time;
5711
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 if (convert_time_zone_displacement(current_thd->time_zone(), &temp_time))
5712 return TYPE_ERR_BAD_VALUE;
5713 } else {
5714 211566 time = ltime;
5715 }
5716
5717
1/2
✓ Branch 0 taken 211567 times.
✗ Branch 1 not taken.
211567 my_date_to_binary(time, ptr);
5718
2/2
✓ Branch 0 taken 1198 times.
✓ Branch 1 taken 210369 times.
211567 if (non_zero_time(*ltime)) {
5719 1198 *warnings |= MYSQL_TIME_NOTE_TRUNCATED;
5720 1198 return TYPE_NOTE_TIME_TRUNCATED;
5721 }
5722 210369 return TYPE_OK;
5723 }
5724
5725 522808 bool Field_newdate::get_date_internal(MYSQL_TIME *ltime) const {
5726 522808 uint32 tmp = uint3korr(ptr);
5727 522808 ltime->day = tmp & 31;
5728 522808 ltime->month = (tmp >> 5) & 15;
5729 522808 ltime->year = (tmp >> 9);
5730 522808 ltime->time_type = MYSQL_TIMESTAMP_DATE;
5731 522808 ltime->hour = ltime->minute = ltime->second = ltime->second_part =
5732 522808 ltime->neg = false;
5733 522808 ltime->time_zone_displacement = 0;
5734 522808 return false;
5735 }
5736
5737 26 type_conversion_status Field_newdate::store_packed(longlong nr) {
5738 26 int warnings = 0;
5739 MYSQL_TIME ltime;
5740
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 TIME_from_longlong_date_packed(&ltime, nr);
5741
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
52 return store_internal(&ltime, &warnings);
5742 }
5743
5744 42606 bool Field_newdate::send_to_protocol(Protocol *protocol) const {
5745
4/6
✓ Branch 0 taken 42606 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1824 times.
✓ Branch 3 taken 40782 times.
✓ Branch 4 taken 1824 times.
✗ Branch 5 not taken.
42606 if (is_null()) return protocol->store_null();
5746 MYSQL_TIME ltime;
5747
1/2
✓ Branch 0 taken 40782 times.
✗ Branch 1 not taken.
40782 get_date(&ltime, 0);
5748
1/2
✓ Branch 0 taken 40782 times.
✗ Branch 1 not taken.
40782 return protocol->store_date(ltime);
5749 }
5750
5751 374 longlong Field_newdate::val_int() const {
5752
3/6
✓ Branch 0 taken 374 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 374 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 374 times.
374 ASSERT_COLUMN_MARKED_FOR_READ;
5753 374 ulong j = uint3korr(ptr);
5754 374 j = (j % 32L) + (j / 32L % 16L) * 100L + (j / (16L * 32L)) * 10000L;
5755 374 return (longlong)j;
5756 }
5757
5758 268188 longlong Field_newdate::val_date_temporal() const {
5759
3/6
✓ Branch 0 taken 268188 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 268188 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 268188 times.
268188 ASSERT_COLUMN_MARKED_FOR_READ;
5760 MYSQL_TIME ltime;
5761
3/6
✓ Branch 0 taken 268188 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 268188 times.
✓ Branch 4 taken 268188 times.
✗ Branch 5 not taken.
268188 return get_date_internal(&ltime) ? 0 : TIME_to_longlong_date_packed(ltime);
5762 }
5763
5764 longlong Field_newdate::val_time_temporal() const {
5765 ASSERT_COLUMN_MARKED_FOR_READ;
5766 return 0;
5767 }
5768
5769 7422 String *Field_newdate::val_str(String *val_buffer, String *) const {
5770
4/6
✓ Branch 0 taken 7422 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7154 times.
✓ Branch 3 taken 268 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 7154 times.
7422 ASSERT_COLUMN_MARKED_FOR_READ;
5771 7422 val_buffer->alloc(field_length);
5772 7422 val_buffer->length(field_length);
5773 7422 uint32 tmp = uint3korr(ptr);
5774 int part;
5775 7422 char *pos = val_buffer->ptr() + 10;
5776
5777 /* Open coded to get more speed */
5778 7422 *pos-- = 0; // End NULL
5779 7422 part = (int)(tmp & 31);
5780 7422 *pos-- = (char)('0' + part % 10);
5781 7422 *pos-- = (char)('0' + part / 10);
5782 7422 *pos-- = '-';
5783 7422 part = (int)(tmp >> 5 & 15);
5784 7422 *pos-- = (char)('0' + part % 10);
5785 7422 *pos-- = (char)('0' + part / 10);
5786 7422 *pos-- = '-';
5787 7422 part = (int)(tmp >> 9);
5788 7422 *pos-- = (char)('0' + part % 10);
5789 7422 part /= 10;
5790 7422 *pos-- = (char)('0' + part % 10);
5791 7422 part /= 10;
5792 7422 *pos-- = (char)('0' + part % 10);
5793 7422 part /= 10;
5794 7422 *pos = (char)('0' + part);
5795 7422 val_buffer->set_charset(&my_charset_numeric);
5796 7422 return val_buffer;
5797 }
5798
5799 239841 bool Field_newdate::get_date(MYSQL_TIME *ltime,
5800 my_time_flags_t fuzzydate) const {
5801
3/4
✓ Branch 0 taken 239841 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2783 times.
✓ Branch 3 taken 237058 times.
479682 return get_internal_check_zero(ltime, fuzzydate) ||
5802 479682 check_fuzzy_date(*ltime, fuzzydate);
5803 }
5804
5805 4562 int Field_newdate::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
5806 uint32 a, b;
5807 4562 a = uint3korr(a_ptr);
5808 4562 b = uint3korr(b_ptr);
5809
4/4
✓ Branch 0 taken 2573 times.
✓ Branch 1 taken 1989 times.
✓ Branch 2 taken 1172 times.
✓ Branch 3 taken 1401 times.
4562 return (a < b) ? -1 : (a > b) ? 1 : 0;
5810 }
5811
5812 1750 size_t Field_newdate::make_sort_key(uchar *to, size_t length) const {
5813 1750 memset(to, 0, length);
5814 1750 to[0] = ptr[2];
5815 1750 to[1] = ptr[1];
5816 1750 to[2] = ptr[0];
5817 1750 return 3;
5818 }
5819
5820 6485 void Field_newdate::sql_type(String &res) const {
5821 6485 res.set_ascii(STRING_WITH_LEN("date"));
5822 6485 }
5823
5824 /****************************************************************************
5825 ** datetime type
5826 ** In string context: YYYY-MM-DD HH:MM:DD
5827 ** In number context: YYYYMMDDHHMMDD
5828 ** Stored as a 8 byte unsigned int. Should sometimes be change to a 6 byte int.
5829 ****************************************************************************/
5830
5831 76 my_time_flags_t Field_datetime::date_flags(const THD *thd) const {
5832 76 my_time_flags_t date_flags = TIME_FUZZY_DATE;
5833
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 55 times.
76 if (thd->variables.sql_mode & MODE_NO_ZERO_DATE)
5834 21 date_flags |= TIME_NO_ZERO_DATE;
5835
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 58 times.
76 if (thd->variables.sql_mode & MODE_NO_ZERO_IN_DATE)
5836 18 date_flags |= TIME_NO_ZERO_IN_DATE;
5837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if (thd->variables.sql_mode & MODE_INVALID_DATES)
5838 date_flags |= TIME_INVALID_DATES;
5839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL)
5840 date_flags |= TIME_FRAC_TRUNCATE;
5841
5842 76 return date_flags;
5843 }
5844
5845 1 void Field_datetime::store_timestamp_internal(const my_timeval *tm) {
5846 MYSQL_TIME mysql_time;
5847
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 THD *thd = current_thd;
5848
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 thd->variables.time_zone->gmt_sec_to_TIME(&mysql_time, *tm);
5849 1 thd->time_zone_used = true;
5850 1 int error = 0;
5851
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 store_internal(&mysql_time, &error);
5852 1 }
5853
5854 /**
5855 Store a DATETIME in a 8-byte integer to record.
5856
5857 @param table Table
5858 @param tmp The number, in YYYYMMDDhhmmss format
5859 @param ptr Where to store to
5860 */
5861 31 static inline type_conversion_status datetime_store_internal(TABLE *table,
5862 ulonglong tmp,
5863 uchar *ptr) {
5864
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
31 if (table && table->s->db_low_byte_first)
5865 31 int8store(ptr, tmp);
5866 else
5867 longlongstore(ptr, tmp);
5868 31 return TYPE_OK;
5869 }
5870
5871 /**
5872 Read a DATETIME from record to a 8-byte integer
5873
5874 @param table Table
5875 @param ptr Where to read from
5876 @retval An integer in format YYYYMMDDhhmmss
5877 */
5878 47 static inline longlong datetime_get_internal(TABLE *table, uchar *ptr) {
5879
2/4
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
47 if (table && table->s->db_low_byte_first)
5880 47 return sint8korr(ptr);
5881 else
5882 return longlongget(ptr);
5883 }
5884
5885 1 bool Field_datetime::get_date_internal(MYSQL_TIME *ltime) const {
5886 1 longlong tmp = datetime_get_internal(table, ptr);
5887 1 ltime->time_type = MYSQL_TIMESTAMP_DATETIME;
5888 1 ltime->neg = false;
5889 1 ltime->second_part = 0;
5890 1 TIME_set_yymmdd(ltime, (uint)(tmp / 1000000LL));
5891 1 TIME_set_hhmmss(ltime, (uint)(tmp % 1000000LL));
5892 1 ltime->time_zone_displacement = 0;
5893 1 return false;
5894 }
5895
5896 31 type_conversion_status Field_datetime::store_internal(const MYSQL_TIME *ltime,
5897 int *) {
5898 31 ulonglong tmp = TIME_to_ulonglong_datetime(*ltime);
5899 31 return datetime_store_internal(table, tmp, ptr);
5900 }
5901
5902 type_conversion_status Field_datetime::store(longlong nr, bool unsigned_val) {
5903 ASSERT_COLUMN_MARKED_FOR_WRITE;
5904 MYSQL_TIME ltime;
5905 int warnings;
5906 type_conversion_status error = TYPE_OK;
5907 longlong tmp =
5908 convert_number_to_datetime(nr, unsigned_val, &ltime, &warnings);
5909 if (tmp == -1LL)
5910 error = TYPE_ERR_BAD_VALUE;
5911 else {
5912 error = time_warning_to_type_conversion_status(warnings);
5913 datetime_store_internal(table, tmp, ptr);
5914 }
5915 if (warnings && set_warnings(ErrConvString(nr, unsigned_val), warnings))
5916 error = TYPE_ERR_BAD_VALUE;
5917 return error;
5918 }
5919
5920 type_conversion_status Field_datetime::store_packed(longlong nr) {
5921 MYSQL_TIME ltime;
5922 TIME_from_longlong_datetime_packed(&ltime, nr);
5923 return Field_datetime::store_time(&ltime, 0);
5924 }
5925
5926 longlong Field_datetime::val_int() const {
5927 ASSERT_COLUMN_MARKED_FOR_READ;
5928 return datetime_get_internal(table, ptr);
5929 }
5930
5931 /*
5932 We don't reuse the parent method for performance purposes,
5933 to avoid conversion from number to MYSQL_TIME.
5934 Using my_datetime_number_to_str() instead of my_datetime_to_str().
5935 */
5936 46 String *Field_datetime::val_str(String *val_buffer, String *) const {
5937
3/6
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 46 times.
46 ASSERT_COLUMN_MARKED_FOR_READ;
5938 46 val_buffer->alloc(field_length + 1);
5939 46 val_buffer->set_charset(&my_charset_numeric);
5940 46 val_buffer->length(MAX_DATETIME_WIDTH);
5941 46 longlong tmp = datetime_get_internal(table, ptr);
5942 46 val_buffer->length(my_datetime_number_to_str(val_buffer->ptr(), tmp));
5943 46 return val_buffer;
5944 }
5945
5946 1 bool Field_datetime::get_date(MYSQL_TIME *ltime,
5947 my_time_flags_t fuzzydate) const {
5948
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
2 return get_internal_check_zero(ltime, fuzzydate) ||
5949 2 check_fuzzy_date(*ltime, fuzzydate);
5950 }
5951
5952 int Field_datetime::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
5953 longlong a, b;
5954 if (table && table->s->db_low_byte_first) {
5955 a = sint8korr(a_ptr);
5956 b = sint8korr(b_ptr);
5957 } else {
5958 a = longlongget(a_ptr);
5959 b = longlongget(b_ptr);
5960 }
5961 return ((ulonglong)a < (ulonglong)b) ? -1
5962 : ((ulonglong)a > (ulonglong)b) ? 1 : 0;
5963 }
5964
5965 2 size_t Field_datetime::make_sort_key(uchar *to, size_t length) const {
5966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert(length == PACK_LENGTH);
5967 #ifdef WORDS_BIGENDIAN
5968 if (!table || !table->s->db_low_byte_first)
5969 copy_integer<true>(to, length, ptr, PACK_LENGTH, true);
5970 else
5971 #endif
5972 2 copy_integer<false>(to, length, ptr, PACK_LENGTH, true);
5973 2 return PACK_LENGTH;
5974 }
5975
5976 22114 void Field_datetime::sql_type(String &res) const {
5977 22114 res.set_ascii(STRING_WITH_LEN("datetime"));
5978 22114 }
5979
5980 /****************************************************************************
5981 ** datetimef type
5982 ** In string context: YYYY-MM-DD HH:MM:DD.FFFFFF
5983 ** In number context: YYYYMMDDHHMMDD.FFFFFF
5984 ** Stored as a 8 byte value.
5985 ****************************************************************************/
5986
5987 5344100 my_time_flags_t Field_datetimef::date_flags(const THD *thd) const {
5988 5344100 my_time_flags_t date_flags = TIME_FUZZY_DATE;
5989
2/2
✓ Branch 0 taken 5264946 times.
✓ Branch 1 taken 79154 times.
5344100 if (thd->variables.sql_mode & MODE_NO_ZERO_DATE)
5990 5264946 date_flags |= TIME_NO_ZERO_DATE;
5991
2/2
✓ Branch 0 taken 5265417 times.
✓ Branch 1 taken 78683 times.
5344100 if (thd->variables.sql_mode & MODE_NO_ZERO_IN_DATE)
5992 5265417 date_flags |= TIME_NO_ZERO_IN_DATE;
5993
2/2
✓ Branch 0 taken 5644 times.
✓ Branch 1 taken 5338456 times.
5344100 if (thd->variables.sql_mode & MODE_INVALID_DATES)
5994 5644 date_flags |= TIME_INVALID_DATES;
5995
2/2
✓ Branch 0 taken 434 times.
✓ Branch 1 taken 5343666 times.
5344100 if (thd->variables.sql_mode & MODE_TIME_TRUNCATE_FRACTIONAL)
5996 434 date_flags |= TIME_FRAC_TRUNCATE;
5997
5998 5344100 return date_flags;
5999 }
6000
6001 307 void Field_datetimef::store_timestamp_internal(const my_timeval *tm) {
6002 MYSQL_TIME mysql_time;
6003
1/2
✓ Branch 0 taken 307 times.
✗ Branch 1 not taken.
307 THD *thd = current_thd;
6004
1/2
✓ Branch 0 taken 307 times.
✗ Branch 1 not taken.
307 thd->variables.time_zone->gmt_sec_to_TIME(&mysql_time, *tm);
6005 307 thd->time_zone_used = true;
6006 307 int warnings = 0;
6007
1/2
✓ Branch 0 taken 307 times.
✗ Branch 1 not taken.
307 store_internal(&mysql_time, &warnings);
6008 307 }
6009
6010 196564 bool Field_datetimef::get_date(MYSQL_TIME *ltime,
6011 my_time_flags_t fuzzydate) const {
6012
3/4
✓ Branch 0 taken 196583 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5158 times.
✓ Branch 3 taken 191429 times.
393151 return get_internal_check_zero(ltime, fuzzydate) ||
6013 393167 check_fuzzy_date(*ltime, fuzzydate);
6014 }
6015
6016 79615 void Field_datetimef::sql_type(String &res) const {
6017
2/2
✓ Branch 0 taken 77874 times.
✓ Branch 1 taken 1741 times.
79615 if (dec == 0) {
6018 77874 res.set_ascii(STRING_WITH_LEN("datetime"));
6019 77875 return;
6020 }
6021 1741 const CHARSET_INFO *cs = res.charset();
6022 1742 res.length(cs->cset->snprintf(cs, res.ptr(), res.alloced_length(),
6023 1742 "datetime(%d)", dec));
6024 }
6025
6026 682415 bool Field_datetimef::get_date_internal(MYSQL_TIME *ltime) const {
6027 682415 TIME_from_longlong_datetime_packed(ltime, val_date_temporal());
6028 682440 return false;
6029 }
6030
6031 2671508 type_conversion_status Field_datetimef::store_internal(const MYSQL_TIME *ltime,
6032 int *) {
6033 /*
6034 If time zone displacement information is present in "ltime"
6035 - adjust the value to UTC based on the time zone
6036 - convert to the local time zone
6037 */
6038 2671508 MYSQL_TIME temp_t = *ltime;
6039
3/6
✓ Branch 0 taken 2671524 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2671472 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2671472 times.
2671508 if (convert_time_zone_displacement(current_thd->time_zone(), &temp_t))
6040 return TYPE_ERR_BAD_VALUE;
6041
2/4
✓ Branch 0 taken 2671532 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2671511 times.
✗ Branch 3 not taken.
2671472 store_packed(TIME_to_longlong_datetime_packed(temp_t));
6042
6043 2671511 return TYPE_OK;
6044 }
6045
6046 455496 type_conversion_status Field_datetimef::reset() {
6047 455496 store_packed(0);
6048 455505 return TYPE_OK;
6049 }
6050
6051 735152 longlong Field_datetimef::val_date_temporal() const {
6052 735152 return my_datetime_packed_from_binary(ptr, dec);
6053 }
6054
6055 3127134 type_conversion_status Field_datetimef::store_packed(longlong nr) {
6056 3127134 my_datetime_packed_to_binary(nr, ptr, dec);
6057 3127140 return TYPE_OK;
6058 }
6059
6060 /****************************************************************************
6061 ** string type
6062 ** A string may be varchar or binary
6063 ****************************************************************************/
6064
6065 /**
6066 Report "not well formed" or "cannot convert" error
6067 after storing a character string info a field.
6068
6069 As of version 5.0 both cases return the same error:
6070
6071 "Invalid string value: 'xxx' for column 't' at row 1"
6072
6073 Future versions will possibly introduce a new error message:
6074
6075 "Cannot convert character string: 'xxx' for column 't' at row 1"
6076
6077 @param well_formed_error_pos position of the first non-wellformed
6078 character in the source string
6079 @param cannot_convert_error_pos position of the first non-convertable
6080 character in the source string
6081 @param from_end_pos position where conversion stopped in
6082 the source string
6083 @param end end of the source string
6084 @param count_spaces treat trailing spaces as important data
6085 @param cs character set of the string
6086
6087 @return TYPE_OK, TYPE_NOTE_TRUNCATED, TYPE_WARN_TRUNCATED,
6088 TYPE_WARN_INVALID_STRING
6089
6090 */
6091
6092 583475809 type_conversion_status Field_longstr::check_string_copy_error(
6093 const char *well_formed_error_pos, const char *cannot_convert_error_pos,
6094 const char *from_end_pos, const char *end, bool count_spaces,
6095 const CHARSET_INFO *cs) {
6096 const char *pos;
6097 char tmp[32];
6098
1/2
✓ Branch 0 taken 583476665 times.
✗ Branch 1 not taken.
583475809 THD *thd = current_thd;
6099
6100
4/6
✓ Branch 0 taken 699205772 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 699197245 times.
✓ Branch 3 taken 8527 times.
✓ Branch 4 taken 699197376 times.
✗ Branch 5 not taken.
583476665 if (!(pos = well_formed_error_pos) && !(pos = cannot_convert_error_pos))
6101
1/2
✓ Branch 0 taken 699197161 times.
✗ Branch 1 not taken.
699197376 return report_if_important_data(from_end_pos, end, count_spaces);
6102
6103
1/2
✓ Branch 0 taken 223821 times.
✗ Branch 1 not taken.
8 convert_to_printable(tmp, sizeof(tmp), pos, (end - pos), cs, 6);
6104
6105
2/4
✓ Branch 0 taken 223821 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 223821 times.
✗ Branch 3 not taken.
223821 push_warning_printf(
6106 thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
6107 ER_THD(thd, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), "string", tmp,
6108 field_name, thd->get_stmt_da()->current_row_for_condition());
6109
6110
2/2
✓ Branch 0 taken 215518 times.
✓ Branch 1 taken 8303 times.
223821 if (well_formed_error_pos != nullptr) return TYPE_WARN_INVALID_STRING;
6111
6112 8303 return TYPE_WARN_TRUNCATED;
6113 }
6114
6115 /*
6116 Check if we lost any important data and send a truncation error/warning
6117
6118 SYNOPSIS
6119 Field_longstr::report_if_important_data()
6120 pstr - Truncated rest of string
6121 end - End of truncated string
6122 count_spaces - Treat trailing spaces as important data
6123
6124 RETURN VALUES
6125 TYPE_OK - None was truncated
6126 != TYPE_OK - Some bytes were truncated
6127
6128 NOTE
6129 Check if we lost any important data (anything in a binary string,
6130 or any non-space in others). If only trailing spaces was lost,
6131 send a truncation note, otherwise send a truncation error.
6132 Silently ignore trailing spaces if the count_space parameter is false.
6133 */
6134
6135 699196840 type_conversion_status Field_longstr::report_if_important_data(
6136 const char *pstr, const char *end, bool count_spaces) {
6137
2/2
✓ Branch 0 taken 9579 times.
✓ Branch 1 taken 699187261 times.
699196840 if (pstr < end) // String is truncated
6138 {
6139 9579 THD *thd = current_thd;
6140
6141
2/2
✓ Branch 0 taken 9460 times.
✓ Branch 1 taken 299 times.
9579 if (test_if_important_data(field_charset, pstr, end)) {
6142 // Warning should only be written when check_for_truncated_fields is set
6143
2/2
✓ Branch 0 taken 4799 times.
✓ Branch 1 taken 4661 times.
9460 if (thd->check_for_truncated_fields) {
6144
6/6
✓ Branch 0 taken 1732 times.
✓ Branch 1 taken 3067 times.
✓ Branch 2 taken 76 times.
✓ Branch 3 taken 1656 times.
✓ Branch 4 taken 76 times.
✓ Branch 5 taken 4723 times.
4799 if (!thd->lex->is_ignore() && thd->is_strict_mode())
6145 76 set_warning(Sql_condition::SL_WARNING, ER_DATA_TOO_LONG, 1);
6146 else
6147 4723 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
6148 }
6149 9460 return TYPE_WARN_TRUNCATED;
6150
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 233 times.
299 } else if (count_spaces) {
6151 // If we lost only spaces then produce a NOTE, not a WARNING
6152
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 54 times.
66 if (thd->check_for_truncated_fields) {
6153 12 set_warning(Sql_condition::SL_NOTE, WARN_DATA_TRUNCATED, 1);
6154 }
6155 66 return TYPE_NOTE_TRUNCATED;
6156 }
6157 }
6158 699187494 return TYPE_OK;
6159 }
6160
6161 /* Copy a string and fill with space */
6162
6163 23154484 type_conversion_status Field_string::store(const char *from, size_t length,
6164 const CHARSET_INFO *cs) {
6165
4/6
✓ Branch 0 taken 23154486 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23034830 times.
✓ Branch 3 taken 119656 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 23034840 times.
23154484 ASSERT_COLUMN_MARKED_FOR_WRITE;
6166 size_t copy_length;
6167 const char *well_formed_error_pos;
6168 const char *cannot_convert_error_pos;
6169 const char *from_end_pos;
6170
6171 46309012 copy_length = field_well_formed_copy_nchars(
6172 23154494 field_charset, (char *)ptr, field_length, cs, from, length,
6173
1/2
✓ Branch 0 taken 23154518 times.
✗ Branch 1 not taken.
23154494 field_length / field_charset->mbmaxlen, &well_formed_error_pos,
6174 &cannot_convert_error_pos, &from_end_pos);
6175
6176 /* Append spaces if the string was shorter than the field. */
6177
2/2
✓ Branch 0 taken 21526960 times.
✓ Branch 1 taken 1627558 times.
23154518 if (copy_length < field_length)
6178 21526960 field_charset->cset->fill(field_charset, (char *)ptr + copy_length,
6179 21526960 field_length - copy_length,
6180
1/2
✓ Branch 0 taken 21526946 times.
✗ Branch 1 not taken.
21526960 field_charset->pad_char);
6181
6182
1/2
✓ Branch 0 taken 23154512 times.
✗ Branch 1 not taken.
23154504 return check_string_copy_error(well_formed_error_pos,
6183 cannot_convert_error_pos, from_end_pos,
6184 46309024 from + length, false, cs);
6185 }
6186
6187 /**
6188 Store double value in Field_string or Field_varstring.
6189
6190 Pretty prints double number into field_length characters buffer.
6191
6192 @param nr number
6193 */
6194
6195 77861 type_conversion_status Field_str::store(double nr) {
6196
3/6
✓ Branch 0 taken 77861 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 77861 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 77861 times.
77861 ASSERT_COLUMN_MARKED_FOR_WRITE;
6197 char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
6198
1/2
✓ Branch 0 taken 77861 times.
✗ Branch 1 not taken.
77861 uint local_char_length = field_length / charset()->mbmaxlen;
6199 77861 size_t length = 0;
6200 77861 bool error = (local_char_length == 0);
6201
6202 // my_gcvt() requires width > 0, and we may have a CHAR(0) column.
6203
2/2
✓ Branch 0 taken 77860 times.
✓ Branch 1 taken 1 times.
77861 if (!error)
6204
1/2
✓ Branch 0 taken 77860 times.
✗ Branch 1 not taken.
77860 length = my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error);
6205
6206
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 77821 times.
77861 if (error) {
6207
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 THD *thd = current_thd;
6208
6209
4/6
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 39 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
40 if (!thd->lex->is_ignore() && thd->is_strict_mode())
6210 set_warning(Sql_condition::SL_WARNING, ER_DATA_TOO_LONG, 1);
6211 else
6212
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
6213 }
6214
1/2
✓ Branch 0 taken 77861 times.
✗ Branch 1 not taken.
155722 return store(buff, length, &my_charset_numeric);
6215 }
6216
6217 /**
6218 Check whether generated columns' expressions are the same.
6219
6220 @param field A new field to compare against
6221
6222 @return true means the same, otherwise not.
6223 */
6224
6225 6207 bool Field::gcol_expr_is_equal(const Create_field *field) const {
6226
2/4
✓ Branch 0 taken 6207 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6207 times.
✗ Branch 3 not taken.
6207 assert(is_gcol() && field->is_gcol());
6227 6207 return gcol_info->expr_item->eq(field->gcol_info->expr_item, true);
6228 }
6229
6230 101547 uint Field_str::is_equal(const Create_field *new_field) const {
6231
1/2
✓ Branch 0 taken 101547 times.
✗ Branch 1 not taken.
101547 DBUG_TRACE;
6232
6233
3/4
✓ Branch 0 taken 101547 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4759 times.
✓ Branch 3 taken 96788 times.
101547 if (change_prevents_inplace(*this, *new_field)) {
6234 4759 return IS_EQUAL_NO;
6235 }
6236
6237
1/2
✓ Branch 0 taken 96788 times.
✗ Branch 1 not taken.
96788 size_t new_char_len = new_field->max_display_width_in_codepoints();
6238
3/4
✓ Branch 0 taken 96788 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 119 times.
✓ Branch 3 taken 96669 times.
96788 if (new_char_len != char_length() // Changed char len cannot be done
6239 // inplace due to padding
6240 ) {
6241 119 return IS_EQUAL_NO;
6242 }
6243
6244
2/2
✓ Branch 0 taken 96270 times.
✓ Branch 1 taken 399 times.
96669 if (new_field->charset == field_charset) {
6245 96270 return IS_EQUAL_YES;
6246 }
6247
6248 399 return IS_EQUAL_PACK_LENGTH;
6249 101547 }
6250
6251 440125 type_conversion_status Field_string::store(longlong nr, bool unsigned_val) {
6252 char buff[64];
6253 size_t l;
6254
1/2
✓ Branch 0 taken 440125 times.
✗ Branch 1 not taken.
440125 const CHARSET_INFO *cs = charset();
6255
3/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 440113 times.
✓ Branch 2 taken 440125 times.
✗ Branch 3 not taken.
440125 l = (cs->cset->longlong10_to_str)(cs, buff, sizeof(buff),
6256 unsigned_val ? 10 : -10, nr);
6257
1/2
✓ Branch 0 taken 440125 times.
✗ Branch 1 not taken.
880250 return Field_string::store(buff, l, cs);
6258 }
6259
6260 90573 type_conversion_status Field_longstr::store_decimal(const my_decimal *d) {
6261 90573 StringBuffer<DECIMAL_MAX_STR_LENGTH + 1> str(&my_charset_numeric);
6262
1/2
✓ Branch 0 taken 90573 times.
✗ Branch 1 not taken.
90573 my_decimal2string(E_DEC_FATAL_ERROR, d, &str);
6263
1/2
✓ Branch 0 taken 90573 times.
✗ Branch 1 not taken.
181146 return store(str.ptr(), str.length(), str.charset());
6264 90573 }
6265
6266 43213578 uint32 Field_longstr::max_data_length() const {
6267
2/2
✓ Branch 0 taken 33628224 times.
✓ Branch 1 taken 9585354 times.
43213578 return field_length + (field_length > 255 ? 2 : 1);
6268 }
6269
6270 13356 double Field_string::val_real() const {
6271
3/6
✓ Branch 0 taken 13356 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13356 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 13356 times.
13356 ASSERT_COLUMN_MARKED_FOR_READ;
6272 int error;
6273 const char *end;
6274
1/2
✓ Branch 0 taken 13356 times.
✗ Branch 1 not taken.
13356 const CHARSET_INFO *cs = charset();
6275 double result;
6276
6277
1/2
✓ Branch 0 taken 13356 times.
✗ Branch 1 not taken.
13356 result = my_strntod(cs, (char *)ptr, field_length, &end, &error);
6278
3/4
✓ Branch 0 taken 13356 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
✓ Branch 3 taken 13087 times.
26712 if ((error ||
6279
2/2
✓ Branch 0 taken 13333 times.
✓ Branch 1 taken 23 times.
13356 (field_length != (uint32)(end - (char *)ptr) &&
6280
3/4
✓ Branch 0 taken 13333 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
✓ Branch 3 taken 13064 times.
13333 !check_if_only_end_space(cs, end, (char *)ptr + field_length)))) {
6281 size_t length =
6282
1/2
✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
269 cs->cset->lengthsp(cs, pointer_cast<const char *>(ptr), field_length);
6283
1/2
✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
269 ErrConvString err((char *)ptr, length, cs);
6284 269 push_warning_printf(
6285
2/4
✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
✗ Branch 3 not taken.
269 current_thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE,
6286
2/4
✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
✗ Branch 3 not taken.
269 ER_THD(current_thd, ER_TRUNCATED_WRONG_VALUE), "DOUBLE", err.ptr());
6287 }
6288 13356 return result;
6289 }
6290
6291 66 longlong Field_string::val_int() const {
6292
3/6
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 66 times.
66 ASSERT_COLUMN_MARKED_FOR_READ;
6293 int error;
6294 const char *end;
6295
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 const CHARSET_INFO *cs = charset();
6296 longlong result;
6297
6298
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 result = my_strntoll(cs, (char *)ptr, field_length, 10, &end, &error);
6299
4/4
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 39 times.
109 if ((error ||
6300
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 (field_length != (uint32)(end - (char *)ptr) &&
6301
3/4
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 39 times.
43 !check_if_only_end_space(cs, end, (char *)ptr + field_length)))) {
6302 size_t length =
6303
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 cs->cset->lengthsp(cs, pointer_cast<const char *>(ptr), field_length);
6304
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 ErrConvString err((char *)ptr, length, cs);
6305 27 push_warning_printf(
6306
2/4
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
27 current_thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE,
6307
2/4
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
27 ER_THD(current_thd, ER_TRUNCATED_WRONG_VALUE), "INTEGER", err.ptr());
6308 }
6309 66 return result;
6310 }
6311
6312 48068802 String *Field_string::val_str(String *, String *val_ptr) const {
6313
4/6
✓ Branch 0 taken 48068802 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47949651 times.
✓ Branch 3 taken 119151 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 47949651 times.
48068802 ASSERT_COLUMN_MARKED_FOR_READ;
6314 size_t length;
6315
2/2
✓ Branch 0 taken 3590952 times.
✓ Branch 1 taken 44477850 times.
48068802 if (current_thd->variables.sql_mode & MODE_PAD_CHAR_TO_FULL_LENGTH)
6316 3590952 length = my_charpos(field_charset, ptr, ptr + field_length,
6317 field_length / field_charset->mbmaxlen);
6318 else
6319 44477849 length = field_charset->cset->lengthsp(field_charset, (const char *)ptr,
6320 44477850 field_length);
6321 48068801 val_ptr->set((const char *)ptr, length, field_charset);
6322 48068801 return val_ptr;
6323 }
6324
6325 72 my_decimal *Field_string::val_decimal(my_decimal *decimal_value) const {
6326
3/6
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 72 times.
72 ASSERT_COLUMN_MARKED_FOR_READ;
6327 72 const CHARSET_INFO *cs = charset();
6328 72 int err = str2my_decimal(E_DEC_FATAL_ERROR, (char *)ptr, field_length, cs,
6329 decimal_value);
6330
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 16 times.
72 if (err) {
6331 size_t length =
6332
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 cs->cset->lengthsp(cs, pointer_cast<const char *>(ptr), field_length);
6333
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 ErrConvString errmsg((char *)ptr, length, cs);
6334 56 push_warning_printf(
6335
2/4
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
56 current_thd, Sql_condition::SL_WARNING, ER_TRUNCATED_WRONG_VALUE,
6336
2/4
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
56 ER_THD(current_thd, ER_TRUNCATED_WRONG_VALUE), "DECIMAL", errmsg.ptr());
6337 }
6338
6339 72 return decimal_value;
6340 }
6341
6342 struct Check_field_param {
6343 const Field *field;
6344 };
6345
6346 5 static bool check_field_for_37426(const void *param_arg) {
6347 5 const Check_field_param *param =
6348 static_cast<const Check_field_param *>(param_arg);
6349
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 assert(param->field->real_type() == MYSQL_TYPE_STRING);
6350
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 DBUG_PRINT("debug",
6351 ("Field %s - type: %d, size: %d", param->field->field_name,
6352 param->field->real_type(), param->field->row_pack_length()));
6353 5 return param->field->row_pack_length() > 255;
6354 }
6355
6356 61465 bool Field_string::compatible_field_size(uint field_metadata,
6357 Relay_log_info *rli_arg, uint16 mflags,
6358 int *order_var) const {
6359 61465 const Check_field_param check_param = {this};
6360
4/4
✓ Branch 0 taken 448 times.
✓ Branch 1 taken 61017 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 61464 times.
61913 if (!is_mts_worker(rli_arg->info_thd) &&
6361
3/4
✓ Branch 0 taken 448 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 447 times.
448 rpl_master_has_bug(rli_arg, 37426, true, check_field_for_37426,
6362 &check_param))
6363 1 return false; // Not compatible field sizes
6364
1/2
✓ Branch 0 taken 61464 times.
✗ Branch 1 not taken.
61464 return Field::compatible_field_size(field_metadata, rli_arg, mflags,
6365 61464 order_var);
6366 }
6367
6368 385955 int Field_string::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
6369 size_t a_len, b_len;
6370
6371
2/2
✓ Branch 0 taken 357689 times.
✓ Branch 1 taken 28266 times.
385955 if (field_charset->mbmaxlen != 1) {
6372 357689 uint char_len = field_length / field_charset->mbmaxlen;
6373 357689 a_len = my_charpos(field_charset, a_ptr, a_ptr + field_length, char_len);
6374 357689 b_len = my_charpos(field_charset, b_ptr, b_ptr + field_length, char_len);
6375 } else
6376 28266 a_len = b_len = field_length;
6377
6378
4/4
✓ Branch 0 taken 188266 times.
✓ Branch 1 taken 197689 times.
✓ Branch 2 taken 188266 times.
✓ Branch 3 taken 197689 times.
574221 if (field_charset->pad_attribute == NO_PAD &&
6379
1/2
✓ Branch 0 taken 188266 times.
✗ Branch 1 not taken.
188266 !(current_thd->variables.sql_mode & MODE_PAD_CHAR_TO_FULL_LENGTH)) {
6380 /*
6381 Our CHAR default behavior is to strip spaces. For PAD SPACE collations,
6382 this doesn't matter, for but NO PAD, we need to do it ourselves here.
6383 */
6384 188266 a_len = field_charset->cset->lengthsp(field_charset, (const char *)a_ptr,
6385 a_len);
6386 188266 b_len = field_charset->cset->lengthsp(field_charset, (const char *)b_ptr,
6387 b_len);
6388 }
6389
6390 385955 return field_charset->coll->strnncollsp(field_charset, a_ptr, a_len, b_ptr,
6391 385955 b_len);
6392 }
6393
6394 69409 size_t Field_string::make_sort_key(uchar *to, size_t length) const {
6395 /*
6396 We don't store explicitly how many bytes long this string is.
6397 Find out by calling charpos, since just using field_length
6398 could give strnxfrm a buffer with more than char_length() code
6399 points, which is not allowed.
6400
6401 The min() is because charpos() is allowed to return a value past
6402 the end of the string for “end of string”.
6403 */
6404 69409 size_t input_length = std::min<size_t>(
6405 138818 field_length,
6406 69409 field_charset->cset->charpos(
6407 69409 field_charset, pointer_cast<const char *>(ptr),
6408 69409 pointer_cast<const char *>(ptr) + field_length, char_length()));
6409
6410
4/4
✓ Branch 0 taken 35718 times.
✓ Branch 1 taken 33691 times.
✓ Branch 2 taken 35718 times.
✓ Branch 3 taken 33691 times.
105127 if (field_charset->pad_attribute == NO_PAD &&
6411
1/2
✓ Branch 0 taken 35718 times.
✗ Branch 1 not taken.
35718 !(current_thd->variables.sql_mode & MODE_PAD_CHAR_TO_FULL_LENGTH)) {
6412 /*
6413 Our CHAR default behavior is to strip spaces. For PAD SPACE collations,
6414 this doesn't matter, for but NO PAD, we need to do it ourselves here.
6415 */
6416 35718 input_length = field_charset->cset->lengthsp(
6417 35718 field_charset, (const char *)ptr, input_length);
6418 }
6419
6420
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69409 times.
69409 assert(char_length_cache == char_length());
6421 138818 size_t tmp [[maybe_unused]] = field_charset->coll->strnxfrm(
6422 69409 field_charset, to, length, char_length_cache, ptr, input_length,
6423 MY_STRXFRM_PAD_TO_MAXLEN);
6424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69409 times.
69409 assert(tmp == length);
6425 69409 return length;
6426 }
6427
6428 720078 void Field_string::sql_type(String &res) const {
6429 720078 THD *thd = current_thd;
6430 720078 const CHARSET_INFO *cs = res.charset();
6431 size_t length;
6432
6433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 720078 times.
1440156 length = cs->cset->snprintf(
6434 cs, res.ptr(), res.alloced_length(), "%s(%d)",
6435 ((type() == MYSQL_TYPE_VAR_STRING && !thd->variables.new_mode)
6436 ? (has_charset() ? "varchar" : "varbinary")
6437
2/2
✓ Branch 0 taken 704803 times.
✓ Branch 1 taken 15275 times.
720078 : (has_charset() ? "char" : "binary")),
6438 720078 (int)field_length / charset()->mbmaxlen);
6439 720078 res.length(length);
6440 720078 }
6441
6442 37527335 uchar *Field_string::pack(uchar *to, const uchar *from,
6443 size_t max_length) const {
6444 37527335 uint length = my_charpos(field_charset, from, from + field_length,
6445 field_length / field_charset->mbmaxlen);
6446
2/2
✓ Branch 0 taken 26631721 times.
✓ Branch 1 taken 10895616 times.
37527337 uint length_bytes = (field_length > 255) ? 2 : 1;
6447
6448 /*
6449 TODO: change charset interface to add a new function that does
6450 the following or add a flag to lengthsp to do it itself
6451 (this is for not packing padding adding bytes in BINARY
6452 fields).
6453 */
6454
2/2
✓ Branch 0 taken 362356 times.
✓ Branch 1 taken 37164981 times.
37527337 if (field_charset->mbmaxlen == 1) {
6455
4/4
✓ Branch 0 taken 43599926 times.
✓ Branch 1 taken 16069 times.
✓ Branch 2 taken 43253639 times.
✓ Branch 3 taken 346287 times.
43615995 while (length && from[length - 1] == field_charset->pad_char) length--;
6456 } else
6457 37164981 length = field_charset->cset->lengthsp(field_charset, (const char *)from,
6458 length);
6459
6460
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 37527336 times.
37527341 if (max_length < length_bytes)
6461 5 length = 0;
6462
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 37527285 times.
37527336 else if (length > max_length - length_bytes)
6463 51 length = max_length - length_bytes;
6464
6465 /* Length always stored little-endian */
6466
2/2
✓ Branch 0 taken 37527339 times.
✓ Branch 1 taken 2 times.
37527341 if (max_length >= 1) {
6467 37527339 *to++ = length & 0xFF;
6468
3/4
✓ Branch 0 taken 26631718 times.
✓ Branch 1 taken 10895621 times.
✓ Branch 2 taken 26631718 times.
✗ Branch 3 not taken.
37527339 if (length_bytes == 2 && max_length >= 2) *to++ = (length >> 8) & 0xFF;
6469 }
6470
6471 /* Store bytes of string */
6472 37527341 memcpy(to, from, length);
6473
6474 37527341 return to + length;
6475 }
6476
6477 /**
6478 Unpack a string field from row data.
6479
6480 This method is used to unpack a string field from a master whose size
6481 of the field is less than that of the slave. Note that there can be a
6482 variety of field types represented with this class. Certain types like
6483 ENUM or SET are processed differently. Hence, the upper byte of the
6484 @c param_data argument contains the result of field->real_type() from
6485 the master.
6486
6487 @note For information about how the length is packed, see @c
6488 Field_string::do_save_field_metadata
6489
6490 @param to Destination of the data
6491 @param from Source of the data
6492 @param param_data Real type (upper) and length (lower) values
6493
6494 @return New pointer into memory based on from + length of the data
6495 */
6496 7598807 const uchar *Field_string::unpack(uchar *to, const uchar *from,
6497 uint param_data) {
6498 uint from_length, length;
6499
6500 /*
6501 Compute the declared length of the field on the master. This is
6502 used to decide if one or two bytes should be read as length.
6503 */
6504
2/2
✓ Branch 0 taken 123419 times.
✓ Branch 1 taken 7475388 times.
7598807 if (param_data)
6505 123419 from_length = (((param_data >> 4) & 0x300) ^ 0x300) + (param_data & 0x00ff);
6506 else
6507 7475388 from_length = field_length;
6508
6509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7598807 times.
7598807 DBUG_PRINT("debug", ("param_data: 0x%x, field_length: %u, from_length: %u",
6510 param_data, field_length, from_length));
6511 /*
6512 Compute the actual length of the data by reading one or two bits
6513 (depending on the declared field length on the master).
6514 */
6515
2/2
✓ Branch 0 taken 107832 times.
✓ Branch 1 taken 7490975 times.
7598807 if (from_length > 255) {
6516 107832 length = uint2korr(from);
6517 107832 from += 2;
6518 } else
6519 7490975 length = (uint)*from++;
6520
6521 7598807 memcpy(to, from, length);
6522 // Pad the string with the pad character of the fields charset
6523 7598807 field_charset->cset->fill(field_charset, (char *)to + length,
6524 7598807 field_length - length, field_charset->pad_char);
6525 7598807 return from + length;
6526 }
6527
6528 /**
6529 Save the field metadata for string fields.
6530
6531 Saves the real type in the first byte and the field length in the
6532 second byte of the field metadata array at index of *metadata_ptr and
6533 *(metadata_ptr + 1).
6534
6535 @note In order to be able to handle lengths exceeding 255 and be
6536 backwards-compatible with pre-5.1.26 servers, an extra two bits of
6537 the length has been added to the metadata in such a way that if
6538 they are set, a new unrecognized type is generated. This will
6539 cause pre-5.1-26 servers to stop due to a field type mismatch,
6540 while new servers will be able to extract the extra bits. If the
6541 length is <256, there will be no difference and both a new and an
6542 old server will be able to handle it.
6543
6544 @note The extra two bits are added to bits 13 and 14 of the
6545 parameter data (with 1 being the least siginficant bit and 16 the
6546 most significant bit of the word) by xoring the extra length bits
6547 with the real type. Since all allowable types have 0xF as most
6548 significant bits of the metadata word, lengths <256 will not affect
6549 the real type at all, while all other values will result in a
6550 non-existent type in the range 17-244.
6551
6552 @see Field_string::unpack
6553
6554 @param metadata_ptr First byte of field metadata
6555
6556 @returns number of bytes written to metadata_ptr
6557 */
6558 4977628 int Field_string::do_save_field_metadata(uchar *metadata_ptr) const {
6559
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4977628 times.
4977628 assert(field_length < 1024);
6560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4977631 times.
4977628 assert((real_type() & 0xF0) == 0xF0);
6561
2/2
✓ Branch 0 taken 59 times.
✓ Branch 1 taken 4977574 times.
4977631 DBUG_PRINT("debug",
6562 ("field_length: %u, real_type: %u", field_length, real_type()));
6563 4977633 *metadata_ptr = (real_type() ^ ((field_length & 0x300) >> 4));
6564 4977633 *(metadata_ptr + 1) = field_length & 0xFF;
6565 4977633 return 2;
6566 }
6567
6568 199698 uint Field_string::max_packed_col_length() const {
6569 199698 const size_t max_length = pack_length();
6570
2/2
✓ Branch 0 taken 5436 times.
✓ Branch 1 taken 194262 times.
199698 return (max_length > 255 ? 2 : 1) + max_length;
6571 }
6572
6573 994625 size_t Field_string::get_key_image(uchar *buff, size_t length,
6574 imagetype) const {
6575 size_t bytes =
6576 994625 my_charpos(field_charset, (char *)ptr, (char *)ptr + field_length,
6577 length / field_charset->mbmaxlen);
6578 994624 memcpy(buff, ptr, bytes);
6579
2/2
✓ Branch 0 taken 645130 times.
✓ Branch 1 taken 349494 times.
994624 if (bytes < length)
6580 645130 field_charset->cset->fill(field_charset, (char *)buff + bytes,
6581 645130 length - bytes, field_charset->pad_char);
6582 994625 return bytes;
6583 }
6584
6585 /****************************************************************************
6586 VARCHAR type
6587 Data in field->ptr is stored as:
6588 1 or 2 bytes length-prefix-header (from Field_varstring::length_bytes)
6589 data
6590
6591 NOTE:
6592 When VARCHAR is stored in a key (for handler::index_read() etc) it's always
6593 stored with a 2 byte prefix. (Just like blob keys).
6594
6595 Normally length_bytes is calculated as (field_length < 256 : 1 ? 2)
6596 The exception is if there is a prefix key field that is part of a long
6597 VARCHAR, in which case field_length for this may be 1 but the length_bytes
6598 is 2.
6599 ****************************************************************************/
6600
6601 /**
6602 Save the field metadata for varstring fields.
6603
6604 Saves the field length in the first byte. Note: may consume
6605 2 bytes. Caller must ensure second byte is contiguous with
6606 first byte (e.g. array index 0,1).
6607
6608 @param metadata_ptr First byte of field metadata
6609
6610 @returns number of bytes written to metadata_ptr
6611 */
6612 1905469 int Field_varstring::do_save_field_metadata(uchar *metadata_ptr) const {
6613
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1905469 times.
1905469 assert(field_length <= 65535);
6614 1905469 int2store((char *)metadata_ptr, field_length);
6615 1905467 return 2;
6616 }
6617
6618 619055545 type_conversion_status Field_varstring::store(const char *from, size_t length,
6619 const CHARSET_INFO *cs) {
6620
4/6
✓ Branch 0 taken 619055715 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 618882045 times.
✓ Branch 3 taken 173670 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 618881982 times.
619055545 ASSERT_COLUMN_MARKED_FOR_WRITE;
6621 size_t copy_length;
6622 const char *well_formed_error_pos;
6623 const char *cannot_convert_error_pos;
6624 const char *from_end_pos;
6625
6626 1238111149 copy_length = field_well_formed_copy_nchars(
6627 619055482 field_charset, (char *)ptr + length_bytes, field_length, cs, from, length,
6628
1/2
✓ Branch 0 taken 619055667 times.
✗ Branch 1 not taken.
619055482 field_length / field_charset->mbmaxlen, &well_formed_error_pos,
6629 &cannot_convert_error_pos, &from_end_pos);
6630
6631
2/2
✓ Branch 0 taken 109895274 times.
✓ Branch 1 taken 509160393 times.
619055667 if (length_bytes == 1)
6632 109895274 *ptr = (uchar)copy_length;
6633 else
6634 509160393 int2store(ptr, static_cast<uint16>(copy_length));
6635
6636
1/2
✓ Branch 0 taken 619055781 times.
✗ Branch 1 not taken.
524795554 return check_string_copy_error(well_formed_error_pos,
6637 cannot_convert_error_pos, from_end_pos,
6638 1238111562 from + length, true, cs);
6639 }
6640
6641 57885 type_conversion_status Field_varstring::store(longlong nr, bool unsigned_val) {
6642 char buff[64];
6643 uint length;
6644
3/4
✓ Branch 0 taken 32901 times.
✓ Branch 1 taken 24984 times.
✓ Branch 2 taken 57885 times.
✗ Branch 3 not taken.
57885 length = (uint)(field_charset->cset->longlong10_to_str)(
6645 field_charset, buff, sizeof(buff), (unsigned_val ? 10 : -10), nr);
6646
1/2
✓ Branch 0 taken 57885 times.
✗ Branch 1 not taken.
115770 return Field_varstring::store(buff, length, field_charset);
6647 }
6648
6649 81227 double Field_varstring::val_real() const {
6650
4/6
✓ Branch 0 taken 81227 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 81165 times.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 81165 times.
81227 ASSERT_COLUMN_MARKED_FOR_READ;
6651 int error;
6652 const char *end;
6653 double result;
6654
1/2
✓ Branch 0 taken 81227 times.
✗ Branch 1 not taken.
81227 const CHARSET_INFO *cs = charset();
6655
6656
1/2
✓ Branch 0 taken 81227 times.
✗ Branch 1 not taken.
81227 uint length = data_length();
6657
1/2
✓ Branch 0 taken 81227 times.
✗ Branch 1 not taken.
81227 result = my_strntod(cs, (char *)ptr + length_bytes, length, &end, &error);
6658
6659
4/6
✓ Branch 0 taken 81227 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 81227 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1075 times.
✓ Branch 5 taken 80152 times.
162454 if ((error || (length != (uint)(end - (char *)ptr + length_bytes) &&
6660
2/2
✓ Branch 0 taken 1075 times.
✓ Branch 1 taken 80152 times.
81227 !check_if_only_end_space(
6661
1/2
✓ Branch 0 taken 81227 times.
✗ Branch 1 not taken.
81227 cs, end, (char *)ptr + length_bytes + length)))) {
6662
2/4
✓ Branch 0 taken 1075 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1075 times.
✗ Branch 3 not taken.
1075 push_numerical_conversion_warning(current_thd, (char *)ptr + length_bytes,
6663 length, cs, "DOUBLE",
6664 ER_TRUNCATED_WRONG_VALUE);
6665 }
6666 81227 return result;
6667 }
6668
6669 15 longlong Field_varstring::val_int() const {
6670
3/6
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15 times.
15 ASSERT_COLUMN_MARKED_FOR_READ;
6671 int error;
6672 const char *end;
6673
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 const CHARSET_INFO *cs = charset();
6674
6675
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 uint length = data_length();
6676 longlong result =
6677
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 my_strntoll(cs, (char *)ptr + length_bytes, length, 10, &end, &error);
6678
6679
5/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 6 times.
21 if ((error || (length != (uint)(end - (char *)ptr + length_bytes) &&
6680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 !check_if_only_end_space(
6681
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 cs, end, (char *)ptr + length_bytes + length)))) {
6682
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 push_numerical_conversion_warning(current_thd, (char *)ptr + length_bytes,
6683 length, cs, "INTEGER",
6684 ER_TRUNCATED_WRONG_VALUE);
6685 }
6686 15 return result;
6687 }
6688
6689 769275659 String *Field_varstring::val_str(String *, String *val_ptr) const {
6690
4/6
✓ Branch 0 taken 769275854 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 769040522 times.
✓ Branch 3 taken 235332 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 769040733 times.
769275659 ASSERT_COLUMN_MARKED_FOR_READ;
6691 769275952 val_ptr->set(pointer_cast<const char *>(data_ptr()), data_length(),
6692 769275870 field_charset);
6693 769275549 return val_ptr;
6694 }
6695
6696 114 my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value) const {
6697
3/6
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 114 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 114 times.
114 ASSERT_COLUMN_MARKED_FOR_READ;
6698 114 const CHARSET_INFO *cs = charset();
6699 114 uint length = data_length();
6700 114 int error = str2my_decimal(E_DEC_FATAL_ERROR, (char *)ptr + length_bytes,
6701 length, cs, decimal_value);
6702
6703
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 75 times.
114 if (error) {
6704 39 push_numerical_conversion_warning(current_thd, (char *)ptr + length_bytes,
6705 length, cs, "DECIMAL",
6706 ER_TRUNCATED_WRONG_VALUE);
6707 }
6708 114 return decimal_value;
6709 }
6710
6711 228886 int Field_varstring::cmp_max(const uchar *a_ptr, const uchar *b_ptr,
6712 uint max_len) const {
6713 uint a_length, b_length;
6714 int diff;
6715
6716
2/2
✓ Branch 0 taken 78861 times.
✓ Branch 1 taken 150025 times.
228886 if (length_bytes == 1) {
6717 78861 a_length = (uint)*a_ptr;
6718 78861 b_length = (uint)*b_ptr;
6719 } else {
6720 150025 a_length = uint2korr(a_ptr);
6721 150025 b_length = uint2korr(b_ptr);
6722 }
6723 228886 a_length = std::min(a_length, max_len);
6724 228886 b_length = std::min(b_length, max_len);
6725 457772 diff = field_charset->coll->strnncollsp(field_charset, a_ptr + length_bytes,
6726
1/2
✓ Branch 0 taken 228886 times.
✗ Branch 1 not taken.
228886 a_length, b_ptr + length_bytes,
6727 b_length);
6728 228886 return diff;
6729 }
6730
6731 /**
6732 @note
6733 varstring and blob keys are ALWAYS stored with a 2 byte length prefix
6734 */
6735
6736 73109 int Field_varstring::key_cmp(const uchar *key_ptr, uint max_key_length) const {
6737
1/2
✓ Branch 0 taken 73109 times.
✗ Branch 1 not taken.
73109 uint length = data_length();
6738 73109 uint local_char_length = max_key_length / field_charset->mbmaxlen;
6739
6740 73109 local_char_length =
6741
1/2
✓ Branch 0 taken 73109 times.
✗ Branch 1 not taken.
73109 my_charpos(field_charset, ptr + length_bytes, ptr + length_bytes + length,
6742 local_char_length);
6743 73109 length = std::min(length, local_char_length);
6744
1/2
✓ Branch 0 taken 73109 times.
✗ Branch 1 not taken.
73109 return field_charset->coll->strnncollsp(field_charset, ptr + length_bytes,
6745 length, key_ptr + HA_KEY_BLOB_LENGTH,
6746 219327 uint2korr(key_ptr));
6747 }
6748
6749 /**
6750 Compare to key segments (always 2 byte length prefix).
6751
6752 @note
6753 This is used only to compare key segments created for index_read().
6754 (keys are created and compared in key.cc)
6755 */
6756
6757 394540 int Field_varstring::key_cmp(const uchar *a, const uchar *b) const {
6758 394540 return field_charset->coll->strnncollsp(field_charset, a + HA_KEY_BLOB_LENGTH,
6759 394540 uint2korr(a), b + HA_KEY_BLOB_LENGTH,
6760 789080 uint2korr(b));
6761 }
6762
6763 191238 size_t Field_varstring::make_sort_key(uchar *to, size_t length) const {
6764 191238 const int flags =
6765
2/2
✓ Branch 0 taken 94722 times.
✓ Branch 1 taken 96516 times.
191238 (field_charset->pad_attribute == NO_PAD) ? 0 : MY_STRXFRM_PAD_TO_MAXLEN;
6766
6767
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 191238 times.
191238 assert(char_length_cache == char_length());
6768 573714 return field_charset->coll->strnxfrm(field_charset, to, length,
6769 191238 char_length_cache, ptr + length_bytes,
6770 191238 data_length(), flags);
6771 }
6772
6773 5444142 enum ha_base_keytype Field_varstring::key_type() const {
6774 enum ha_base_keytype res;
6775
6776
2/2
✓ Branch 0 taken 295728 times.
✓ Branch 1 taken 5148415 times.
5444142 if (binary())
6777
2/2
✓ Branch 0 taken 292397 times.
✓ Branch 1 taken 3331 times.
295728 res = length_bytes == 1 ? HA_KEYTYPE_VARBINARY1 : HA_KEYTYPE_VARBINARY2;
6778 else
6779
2/2
✓ Branch 0 taken 1988950 times.
✓ Branch 1 taken 3159465 times.
5148415 res = length_bytes == 1 ? HA_KEYTYPE_VARTEXT1 : HA_KEYTYPE_VARTEXT2;
6780 5444143 return res;
6781 }
6782
6783 1991886 void Field_varstring::sql_type(String &res) const {
6784 1991886 const CHARSET_INFO *cs = res.charset();
6785 size_t length;
6786
6787 1991899 length = cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), "%s(%d)",
6788
2/2
✓ Branch 0 taken 1962261 times.
✓ Branch 1 taken 29638 times.
1991899 (has_charset() ? "varchar" : "varbinary"),
6789 1991893 (int)field_length / charset()->mbmaxlen);
6790 1991902 res.length(length);
6791 1991906 }
6792
6793 877699355 uint32 Field_varstring::data_length(ptrdiff_t row_offset) const {
6794
2/2
✓ Branch 0 taken 349523013 times.
✓ Branch 1 taken 528176342 times.
1405876879 return length_bytes == 1 ? (uint32) * (ptr + row_offset)
6795 1405876879 : uint2korr(ptr + row_offset);
6796 }
6797
6798 /*
6799 Functions to create a packed row.
6800 Here the number of length bytes are depending on the given max_length
6801 */
6802
6803 75664402 uchar *Field_varstring::pack(uchar *to, const uchar *from,
6804 size_t max_length) const {
6805
2/2
✓ Branch 0 taken 10581655 times.
✓ Branch 1 taken 65082747 times.
75664402 uint length = length_bytes == 1 ? (uint)*from : uint2korr(from);
6806
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 75664395 times.
75664405 if (max_length < length_bytes)
6807 10 length = 0;
6808
2/2
✓ Branch 0 taken 29027 times.
✓ Branch 1 taken 75635368 times.
75664395 else if (length > max_length - length_bytes)
6809 29027 length = max_length - length_bytes;
6810
6811 /* Length always stored little-endian */
6812
2/2
✓ Branch 0 taken 75664394 times.
✓ Branch 1 taken 11 times.
75664405 if (max_length >= 1) {
6813 75664394 *to++ = length & 0xFF;
6814
3/4
✓ Branch 0 taken 65082745 times.
✓ Branch 1 taken 10581649 times.
✓ Branch 2 taken 65082747 times.
✗ Branch 3 not taken.
75664394 if (length_bytes == 2 && max_length >= 2) *to++ = (length >> 8) & 0xFF;
6815 }
6816
6817 /* Store bytes of string */
6818 75664405 memcpy(to, from + length_bytes, length);
6819 75664405 return to + length;
6820 }
6821
6822 /**
6823 Unpack a varstring field from row data.
6824
6825 This method is used to unpack a varstring field from a master
6826 whose size of the field is less than that of the slave.
6827
6828 @note
6829 The string length is always packed little-endian.
6830
6831 @param to Destination of the data
6832 @param from Source of the data
6833 @param param_data Length bytes from the master's field data
6834
6835 @return New pointer into memory based on from + length of the data
6836 */
6837 109890972 const uchar *Field_varstring::unpack(uchar *to, const uchar *from,
6838 uint param_data) {
6839 uint length;
6840
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 209220 times.
209224 uint l_bytes = (param_data && (param_data < field_length))
6841
4/4
✓ Branch 0 taken 209224 times.
✓ Branch 1 taken 109681748 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
110100196 ? (param_data <= 255) ? 1 : 2
6842 : length_bytes;
6843
2/2
✓ Branch 0 taken 51613946 times.
✓ Branch 1 taken 58277026 times.
109890972 if (l_bytes == 1) {
6844 51613946 to[0] = *from++;
6845 51613946 length = to[0];
6846
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 51613945 times.
51613946 if (length_bytes == 2) to[1] = 0;
6847 } else /* l_bytes == 2 */
6848 {
6849 58277026 length = uint2korr(from);
6850 58277035 to[0] = *from++;
6851 58277035 to[1] = *from++;
6852 }
6853
2/2
✓ Branch 0 taken 108235545 times.
✓ Branch 1 taken 1655436 times.
109890981 if (length) memcpy(to + length_bytes, from, length);
6854 109890981 return from + length;
6855 }
6856
6857 46421375 size_t Field_varstring::get_key_image(uchar *buff, size_t length,
6858 imagetype) const {
6859 /*
6860 If NULL, data bytes may have been left random by the storage engine, so
6861 don't try to read them.
6862 */
6863
4/6
✓ Branch 0 taken 46421566 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 46421532 times.
✓ Branch 4 taken 46421504 times.
✗ Branch 5 not taken.
46421375 uint f_length = is_null() ? 0 : data_length();
6864 46421538 uint local_char_length = length / field_charset->mbmaxlen;
6865 46421538 uchar *pos = ptr + length_bytes;
6866 46421528 local_char_length =
6867
1/2
✓ Branch 0 taken 46421528 times.
✗ Branch 1 not taken.
46421538 my_charpos(field_charset, pos, pos + f_length, local_char_length);
6868 46421528 f_length = std::min(f_length, local_char_length);
6869 /* Key is always stored with 2 bytes */
6870 46421504 int2store(buff, f_length);
6871 46421584 memcpy(buff + HA_KEY_BLOB_LENGTH, pos, f_length);
6872
2/2
✓ Branch 0 taken 46420996 times.
✓ Branch 1 taken 588 times.
46421584 if (f_length < length) {
6873 /*
6874 Must clear this as we do a memcmp in opt_range.cc to detect
6875 identical keys
6876 */
6877 46420996 memset(buff + HA_KEY_BLOB_LENGTH + f_length, 0, (length - f_length));
6878 }
6879 46421584 return HA_KEY_BLOB_LENGTH + f_length;
6880 }
6881
6882 128 void Field_varstring::set_key_image(const uchar *buff, size_t length) {
6883 128 length = uint2korr(buff); // Real length is here
6884 128 (void)Field_varstring::store((const char *)buff + HA_KEY_BLOB_LENGTH, length,
6885 field_charset);
6886 128 }
6887
6888 676570 int Field_varstring::cmp_binary(const uchar *a_ptr, const uchar *b_ptr,
6889 uint32 max_length) const {
6890 uint32 a_length, b_length;
6891
6892
2/2
✓ Branch 0 taken 641962 times.
✓ Branch 1 taken 34608 times.
676570 if (length_bytes == 1) {
6893 641962 a_length = (uint)*a_ptr;
6894 641962 b_length = (uint)*b_ptr;
6895 } else {
6896 34608 a_length = uint2korr(a_ptr);
6897 34608 b_length = uint2korr(b_ptr);
6898 }
6899 676570 a_length = std::min(a_length, max_length);
6900 676570 b_length = std::min(b_length, max_length);
6901
2/2
✓ Branch 0 taken 224528 times.
✓ Branch 1 taken 452042 times.
676570 if (a_length != b_length) return 1;
6902 452042 return memcmp(a_ptr + length_bytes, b_ptr + length_bytes, a_length);
6903 }
6904
6905 2312022 Field *Field_varstring::new_field(MEM_ROOT *root, TABLE *new_table) const {
6906 Field_varstring *res =
6907 2312022 down_cast<Field_varstring *>(Field::new_field(root, new_table));
6908
2/2
✓ Branch 0 taken 2312075 times.
✓ Branch 1 taken 6 times.
2312081 if (res) res->length_bytes = length_bytes;
6909 2312081 return res;
6910 }
6911
6912 695842 Field *Field_varstring::new_key_field(MEM_ROOT *root, TABLE *new_table,
6913 uchar *new_ptr, uchar *new_null_ptr,
6914 uint new_null_bit) const {
6915 Field_varstring *res;
6916
1/2
✓ Branch 0 taken 695954 times.
✗ Branch 1 not taken.
695842 if ((res = (Field_varstring *)Field::new_key_field(
6917 root, new_table, new_ptr, new_null_ptr, new_null_bit))) {
6918 /* Keys length prefixes are always packed with 2 bytes */
6919 695954 res->length_bytes = 2;
6920 }
6921 695950 return res;
6922 }
6923
6924 35242 uint Field_varstring::is_equal(const Create_field *new_field) const {
6925
1/2
✓ Branch 0 taken 35242 times.
✗ Branch 1 not taken.
35242 DBUG_TRACE;
6926
3/4
✓ Branch 0 taken 35242 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 359 times.
✓ Branch 3 taken 34883 times.
35242 if (change_prevents_inplace(*this, *new_field)) {
6927 359 return IS_EQUAL_NO;
6928 }
6929
6930
4/4
✓ Branch 0 taken 34745 times.
✓ Branch 1 taken 138 times.
✓ Branch 2 taken 34573 times.
✓ Branch 3 taken 310 times.
69628 if (new_field->charset == field_charset &&
6931
3/4
✓ Branch 0 taken 34745 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34573 times.
✓ Branch 3 taken 172 times.
34745 new_field->pack_length() == pack_length()) {
6932 34573 return IS_EQUAL_YES;
6933 }
6934
6935 310 return IS_EQUAL_PACK_LENGTH;
6936 35242 }
6937
6938 6060 void Field_varstring::hash(ulong *nr, ulong *nr2) const {
6939
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 6045 times.
6060 if (is_null()) {
6940 15 *nr ^= (*nr << 1) | 1;
6941 } else {
6942
1/2
✓ Branch 0 taken 6045 times.
✗ Branch 1 not taken.
6045 uint len = data_length();
6943
1/2
✓ Branch 0 taken 6045 times.
✗ Branch 1 not taken.
6045 const CHARSET_INFO *cs = charset();
6944 6045 uint64 tmp1 = *nr;
6945 6045 uint64 tmp2 = *nr2;
6946
1/2
✓ Branch 0 taken 6045 times.
✗ Branch 1 not taken.
6045 cs->coll->hash_sort(cs, ptr + length_bytes, len, &tmp1, &tmp2);
6947
6948 // NOTE: This truncates to 32-bit on Windows, to keep on-disk stability.
6949 6045 *nr = static_cast<ulong>(tmp1);
6950 6045 *nr2 = static_cast<ulong>(tmp2);
6951 }
6952 6060 }
6953
6954 /****************************************************************************
6955 ** blob type
6956 ** A blob is saved as a length and a pointer. The length is stored in the
6957 ** packlength slot and may be from 1-4.
6958 ****************************************************************************/
6959
6960 Field_blob::Field_blob(uint32 packlength_arg)
6961 : Field_longstr(nullptr, 0, &dummy_null_buffer, 0, NONE, "temp",
6962 system_charset_info),
6963 packlength(packlength_arg),
6964 m_keep_old_value(false) {}
6965
6966 5649731 Field_blob::Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
6967 uchar auto_flags_arg, const char *field_name_arg,
6968 TABLE_SHARE *share, uint blob_pack_length,
6969 5649731 const CHARSET_INFO *cs)
6970 16949197 : Field_longstr(ptr_arg, BLOB_PACK_LENGTH_TO_MAX_LENGH(blob_pack_length),
6971 null_ptr_arg, null_bit_arg, auto_flags_arg, field_name_arg,
6972 cs),
6973 5649734 packlength(blob_pack_length),
6974
1/2
✓ Branch 0 taken 5649734 times.
✗ Branch 1 not taken.
5649731 m_keep_old_value(false) {
6975
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5649729 times.
5649729 assert(blob_pack_length <= 4); // Only pack lengths 1-4 supported currently
6976 5649729 set_flag(BLOB_FLAG);
6977 5649729 share->blob_fields++;
6978 /* TODO: why do not fill table->s->blob_field array here? */
6979 5649729 }
6980
6981 83111080 void store_blob_length(uchar *i_ptr, uint i_packlength, uint32 i_number) {
6982
4/5
✓ Branch 0 taken 7033960 times.
✓ Branch 1 taken 24847930 times.
✓ Branch 2 taken 25288355 times.
✓ Branch 3 taken 25941073 times.
✗ Branch 4 not taken.
83111080 switch (i_packlength) {
6983 7033960 case 1:
6984
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7033960 times.
7033960 assert(i_number <= 0xff);
6985 7033960 i_ptr[0] = static_cast<uchar>(i_number);
6986 7033960 break;
6987 24847930 case 2:
6988
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24847930 times.
24847930 assert(i_number <= 0xffff);
6989 24847930 int2store(i_ptr, static_cast<unsigned short>(i_number));
6990 24847684 break;
6991 25288355 case 3:
6992
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25288355 times.
25288355 assert(i_number <= 0xffffff);
6993 25288355 int3store(i_ptr, i_number);
6994 25288355 break;
6995 25941073 case 4:
6996 25941073 int4store(i_ptr, i_number);
6997 }
6998 83110838 }
6999
7000 264900513 uint32 Field_blob::get_length(const uchar *pos, uint packlength_arg) {
7001
4/5
✓ Branch 0 taken 18690695 times.
✓ Branch 1 taken 99720361 times.
✓ Branch 2 taken 111473659 times.
✓ Branch 3 taken 35015830 times.
✗ Branch 4 not taken.
264900513 switch (packlength_arg) {
7002 18690695 case 1:
7003 18690695 return (uint32)pos[0];
7004 99720361 case 2:
7005 99720361 return uint2korr(pos);
7006 111473659 case 3:
7007 111473659 return uint3korr(pos);
7008 35015830 case 4:
7009 35015830 return uint4korr(pos);
7010 }
7011 /* When expanding this, see also MAX_FIELD_BLOBLENGTH. */
7012 return 0; // Impossible
7013 }
7014
7015 /**
7016 Store a blob value to memory storage.
7017 @param from the string value to store.
7018 @param length length of the string value.
7019 @param cs character set of the string value.
7020 @param max_length Cut at this length safely (multibyte aware).
7021 */
7022 4997 type_conversion_status Field_blob::store_to_mem(const char *from, size_t length,
7023 const CHARSET_INFO *cs,
7024 size_t max_length,
7025 Blob_mem_storage *) {
7026 /*
7027 We don't need to support escaping or character set conversions here,
7028 because store_to_mem() is currently called only when we process
7029 queries having GROUP_CONCAT with ORDER BY or DISTINCT,
7030 hence some assersions:
7031 */
7032
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4997 times.
4997 assert(field_charset == cs);
7033
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4997 times.
4997 assert(length <= max_data_length());
7034
7035
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 4978 times.
4997 if (length > max_length) {
7036 int well_formed_error;
7037
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 length = cs->cset->well_formed_len(cs, from, from + max_length, length,
7038 &well_formed_error);
7039 19 table->blob_storage->set_truncated_value(true);
7040 }
7041 char *tmp;
7042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4997 times.
4997 if (!(tmp = table->blob_storage->store(from, length))) {
7043 reset();
7044 return TYPE_ERR_OOM;
7045 }
7046 4997 store_ptr_and_length(tmp, length);
7047 4997 return TYPE_OK;
7048 }
7049
7050 73547672 type_conversion_status Field_blob::store_internal(const char *from,
7051 size_t length,
7052 const CHARSET_INFO *cs) {
7053 size_t new_length;
7054 char buff[STRING_BUFFER_USUAL_SIZE], *tmp;
7055 73547672 String tmpstr(buff, sizeof(buff), &my_charset_bin);
7056
7057
1/2
✓ Branch 0 taken 73547566 times.
✗ Branch 1 not taken.
73547481 THD *thd = current_thd;
7058
7059 /*
7060 If the 'from' address is in the range of the temporary 'value'-
7061 object we need to copy the content to a different location or it will be
7062 invalidated when the 'value'-object is reallocated to make room for
7063 the new character set.
7064 */
7065 73547566 size_t max_len = max_data_length();
7066
6/6
✓ Branch 0 taken 50243380 times.
✓ Branch 1 taken 23304041 times.
✓ Branch 2 taken 16344164 times.
✓ Branch 3 taken 33898694 times.
✓ Branch 4 taken 16344167 times.
✓ Branch 5 taken 57202732 times.
73547502 if (from >= value.ptr() && from <= value.ptr() + value.length()) {
7067 /*
7068 If content of the 'from'-address is cached in the 'value'-object
7069 it is possible that the content needs a character conversion.
7070 */
7071
3/4
✓ Branch 0 taken 16344171 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16336809 times.
✓ Branch 3 taken 7362 times.
16344167 if (!String::needs_conversion_on_storage(length, cs, field_charset)) {
7072
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 16336806 times.
16336809 if (length > max_len) {
7073
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 store_ptr_and_length(from, max_len);
7074
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (thd->check_for_truncated_fields) {
7075
6/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
3 if (thd->is_strict_mode() && !thd->lex->is_ignore())
7076
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_warning(Sql_condition::SL_WARNING, ER_DATA_TOO_LONG, 1);
7077 else
7078
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
7079 }
7080 3 return TYPE_WARN_TRUNCATED;
7081 }
7082
1/2
✓ Branch 0 taken 16336788 times.
✗ Branch 1 not taken.
16336806 store_ptr_and_length(from, length);
7083 16336788 return TYPE_OK;
7084 }
7085
2/4
✓ Branch 0 taken 7363 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7363 times.
7362 if (tmpstr.copy(from, length, cs)) goto oom_error;
7086 7363 from = tmpstr.ptr();
7087 }
7088
7089 57210095 new_length = min<size_t>(max_len, field_charset->mbmaxlen * length);
7090
7091
2/4
✓ Branch 0 taken 57209909 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 57209909 times.
57209803 if (value.alloc(new_length)) goto oom_error;
7092
7093 57209909 tmp = value.ptr();
7094
7095 {
7096 const char *well_formed_error_pos;
7097 const char *cannot_convert_error_pos;
7098 const char *from_end_pos;
7099 /*
7100 "length" is OK as "nchars" argument to well_formed_copy_nchars as this
7101 is never used to limit the length of the data. The cut of long data
7102 is done with the new_length value.
7103 */
7104
1/2
✓ Branch 0 taken 57211017 times.
✗ Branch 1 not taken.
57209804 size_t copy_length = field_well_formed_copy_nchars(
7105 field_charset, tmp, new_length, cs, from, length, length,
7106 &well_formed_error_pos, &cannot_convert_error_pos, &from_end_pos);
7107
7108
1/2
✓ Branch 0 taken 57210727 times.
✗ Branch 1 not taken.
57211017 store_ptr_and_length(tmp, copy_length);
7109
1/2
✓ Branch 0 taken 57210777 times.
✗ Branch 1 not taken.
57210727 return check_string_copy_error(well_formed_error_pos,
7110 cannot_convert_error_pos, from_end_pos,
7111 57210777 from + length, true, cs);
7112 }
7113
7114 oom_error:
7115 /* Fatal OOM error */
7116 reset();
7117 return TYPE_ERR_OOM;
7118 73547568 }
7119
7120 76234320 type_conversion_status Field_blob::store(const char *from, size_t length,
7121 const CHARSET_INFO *cs) {
7122
4/6
✓ Branch 0 taken 76234595 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76217669 times.
✓ Branch 3 taken 16926 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 76218059 times.
76234320 ASSERT_COLUMN_MARKED_FOR_WRITE;
7123
7124
2/2
✓ Branch 0 taken 4997 times.
✓ Branch 1 taken 76229713 times.
76234710 if (table->blob_storage) // GROUP_CONCAT with ORDER BY | DISTINCT
7125 14991 return store_to_mem(from, length, cs,
7126 4997 current_thd->variables.group_concat_max_len,
7127 9994 table->blob_storage);
7128
7129 76229713 return store_internal(from, length, cs);
7130 }
7131
7132 397 type_conversion_status Field_blob::store(double nr) {
7133 397 const CHARSET_INFO *cs = charset();
7134 397 value.set_real(nr, DECIMAL_NOT_SPECIFIED, cs);
7135 397 return Field_blob::store(value.ptr(), value.length(), cs);
7136 }
7137
7138 2571 type_conversion_status Field_blob::store(longlong nr, bool unsigned_val) {
7139 2571 const CHARSET_INFO *cs = charset();
7140 2571 value.set_int(nr, unsigned_val, cs);
7141 2571 return Field_blob::store(value.ptr(), value.length(), cs);
7142 }
7143
7144 16245709 type_conversion_status Field_blob::store(const Field *from) {
7145 16245709 from->val_str(&value);
7146
7147 /*
7148 Copy value if copy_blobs is set, or source is part of the table's
7149 writeset.
7150 */
7151
8/8
✓ Branch 0 taken 9412 times.
✓ Branch 1 taken 16236297 times.
✓ Branch 2 taken 9057 times.
✓ Branch 3 taken 355 times.
✓ Branch 4 taken 5274 times.
✓ Branch 5 taken 3783 times.
✓ Branch 6 taken 16241571 times.
✓ Branch 7 taken 4138 times.
16245709 if (table->copy_blobs || (!value.is_alloced() && from->is_updatable()))
7152 16241571 value.copy();
7153
7154 16245709 return store(value.ptr(), value.length(), from->charset());
7155 }
7156
7157 1309 double Field_blob::val_real() const {
7158
3/6
✓ Branch 0 taken 1309 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1309 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1309 times.
1309 ASSERT_COLUMN_MARKED_FOR_READ;
7159
7160
1/2
✓ Branch 0 taken 1309 times.
✗ Branch 1 not taken.
1309 const char *blob = pointer_cast<const char *>(get_blob_data());
7161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1309 times.
1309 if (blob == nullptr) return 0.0;
7162
7163 int not_used;
7164 const char *end_not_used;
7165
4/8
✓ Branch 0 taken 1309 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1309 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1309 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1309 times.
✗ Branch 7 not taken.
1309 return my_strntod(charset(), blob, get_length(ptr), &end_not_used, &not_used);
7166 }
7167
7168 85 longlong Field_blob::val_int() const {
7169
3/6
✓ Branch 0 taken 85 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 85 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 85 times.
85 ASSERT_COLUMN_MARKED_FOR_READ;
7170
7171
1/2
✓ Branch 0 taken 85 times.
✗ Branch 1 not taken.
85 const char *blob = pointer_cast<const char *>(get_blob_data());
7172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 85 times.
85 if (blob == nullptr) return 0;
7173
7174 int not_used;
7175
4/8
✓ Branch 0 taken 85 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 85 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 85 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 85 times.
✗ Branch 7 not taken.
85 return my_strntoll(charset(), blob, get_length(ptr), 10, nullptr, &not_used);
7176 }
7177
7178 231173952 String *Field_blob::val_str(String *, String *val_ptr) const {
7179
4/6
✓ Branch 0 taken 231173953 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 231156919 times.
✓ Branch 3 taken 17034 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 231156936 times.
231173952 ASSERT_COLUMN_MARKED_FOR_READ;
7180
7181 231173969 const char *blob = pointer_cast<const char *>(get_blob_data());
7182
2/2
✓ Branch 0 taken 1273014 times.
✓ Branch 1 taken 229900967 times.
231173981 if (blob == nullptr)
7183 1273014 val_ptr->set("", 0, charset()); // A bit safer than ->length(0)
7184 else
7185 229900967 val_ptr->set(blob, get_length(ptr), charset());
7186 231173980 return val_ptr;
7187 }
7188
7189 13 my_decimal *Field_blob::val_decimal(my_decimal *decimal_value) const {
7190
3/6
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 13 times.
13 ASSERT_COLUMN_MARKED_FOR_READ;
7191 size_t length;
7192 13 const char *blob = pointer_cast<const char *>(get_blob_data());
7193
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if (!blob) {
7194 blob = "";
7195 length = 0;
7196 } else
7197 13 length = get_length(ptr);
7198
7199 13 str2my_decimal(E_DEC_FATAL_ERROR, blob, length, charset(), decimal_value);
7200 13 return decimal_value;
7201 }
7202
7203 2718727 int Field_blob::cmp(const uchar *a, uint32 a_length, const uchar *b,
7204 uint32 b_length) const {
7205 2718727 return field_charset->coll->strnncollsp(field_charset, a, a_length, b,
7206 2718727 b_length);
7207 }
7208
7209 2693302 int Field_blob::cmp_max(const uchar *a_ptr, const uchar *b_ptr,
7210 uint max_length) const {
7211 2693302 const uchar *blob1 = get_blob_data(a_ptr + packlength);
7212 2693302 const uchar *blob2 = get_blob_data(b_ptr + packlength);
7213 2693302 uint32 a_len = min(get_length(a_ptr), max_length);
7214 2693302 uint32 b_len = min(get_length(b_ptr), max_length);
7215 2693302 return Field_blob::cmp(blob1, a_len, blob2, b_len);
7216 }
7217
7218 255670 int Field_blob::cmp_binary(const uchar *a_ptr, const uchar *b_ptr,
7219 uint32 max_length) const {
7220 255670 const uchar *a = get_blob_data(a_ptr + packlength);
7221 255671 const uchar *b = get_blob_data(b_ptr + packlength);
7222
1/2
✓ Branch 0 taken 255671 times.
✗ Branch 1 not taken.
255671 uint32 a_length = min(get_length(a_ptr), max_length);
7223
1/2
✓ Branch 0 taken 255671 times.
✗ Branch 1 not taken.
255671 uint32 b_length = min(get_length(b_ptr), max_length);
7224 255671 const uint32 min_a_b = min(a_length, b_length);
7225
2/2
✓ Branch 0 taken 201953 times.
✓ Branch 1 taken 53718 times.
255671 uint diff = min_a_b == 0 ? 0 : memcmp(a, b, min_a_b); // memcmp(a, b, 0) == 0
7226
2/2
✓ Branch 0 taken 95944 times.
✓ Branch 1 taken 159727 times.
255671 return diff ? diff : (int)(a_length - b_length);
7227 }
7228
7229 /* The following is used only when comparing a key */
7230
7231 8679 size_t Field_blob::get_key_image(uchar *buff, size_t length,
7232 imagetype type_arg) const {
7233
1/2
✓ Branch 0 taken 8679 times.
✗ Branch 1 not taken.
8679 uint32 blob_length = get_length();
7234
1/2
✓ Branch 0 taken 8680 times.
✗ Branch 1 not taken.
8679 const uchar *const blob = get_blob_data();
7235
7236
2/2
✓ Branch 0 taken 648 times.
✓ Branch 1 taken 8032 times.
8680 if (type_arg == itMBR) {
7237 648 const uint image_length = SIZEOF_STORED_DOUBLE * 4;
7238
7239
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 648 times.
648 if (blob_length < SRID_SIZE) {
7240 memset(buff, 0, image_length);
7241 return image_length;
7242 }
7243 648 gis::srid_t srid = uint4korr(blob);
7244 648 const dd::Spatial_reference_system *srs = nullptr;
7245 dd::cache::Dictionary_client::Auto_releaser m_releaser(
7246
2/4
✓ Branch 0 taken 648 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 648 times.
✗ Branch 3 not taken.
648 current_thd->dd_client());
7247
1/2
✓ Branch 0 taken 648 times.
✗ Branch 1 not taken.
648 Srs_fetcher fetcher(current_thd);
7248
3/4
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 618 times.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
648 if (srid != 0) fetcher.acquire(srid, &srs);
7249
2/4
✓ Branch 0 taken 648 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 648 times.
648 if (get_mbr_from_store(srs, blob, blob_length, 2,
7250 pointer_cast<double *>(buff), &srid)) {
7251 memset(buff, 0, image_length);
7252 } else {
7253 // get_mbr_from_store returns the MBR in machine byte order, but buff
7254 // should always be in little-endian order.
7255 648 float8store(buff, *pointer_cast<double *>(buff));
7256 648 float8store(buff + 8, *(pointer_cast<double *>(buff) + 1));
7257 648 float8store(buff + 16, *(pointer_cast<double *>(buff) + 2));
7258 648 float8store(buff + 24, *(pointer_cast<double *>(buff) + 3));
7259 }
7260
7261 648 return image_length;
7262 648 }
7263
7264 8032 uint local_char_length = length / field_charset->mbmaxlen;
7265
2/2
✓ Branch 0 taken 8028 times.
✓ Branch 1 taken 4 times.
8032 local_char_length = blob == nullptr
7266 ? 0
7267
1/2
✓ Branch 0 taken 8029 times.
✗ Branch 1 not taken.
8028 : my_charpos(field_charset, blob, blob + blob_length,
7268 local_char_length);
7269 8033 blob_length = std::min(blob_length, local_char_length);
7270
7271
2/2
✓ Branch 0 taken 3280 times.
✓ Branch 1 taken 4752 times.
8032 if ((uint32)length > blob_length) {
7272 /*
7273 Must clear this as we do a memcmp in opt_range.cc to detect
7274 identical keys
7275 */
7276 3280 memset(buff + HA_KEY_BLOB_LENGTH + blob_length, 0, (length - blob_length));
7277 3280 length = (uint)blob_length;
7278 }
7279 8032 int2store(buff, static_cast<uint16>(length));
7280
2/2
✓ Branch 0 taken 8003 times.
✓ Branch 1 taken 29 times.
8032 if (length > 0) memcpy(buff + HA_KEY_BLOB_LENGTH, blob, length);
7281 8032 return HA_KEY_BLOB_LENGTH + length;
7282 }
7283
7284 void Field_blob::set_key_image(const uchar *buff, size_t length) {
7285 length = uint2korr(buff);
7286 (void)Field_blob::store((const char *)buff + HA_KEY_BLOB_LENGTH, length,
7287 field_charset);
7288 }
7289
7290 24440 int Field_blob::key_cmp(const uchar *key_ptr, uint max_key_length) const {
7291
1/2
✓ Branch 0 taken 24440 times.
✗ Branch 1 not taken.
24440 uint32 blob_length = get_length(ptr);
7292
1/2
✓ Branch 0 taken 24440 times.
✗ Branch 1 not taken.
24440 const uchar *blob1 = get_blob_data();
7293
1/2
✓ Branch 0 taken 24440 times.
✗ Branch 1 not taken.
24440 const CHARSET_INFO *cs = charset();
7294 24440 uint local_char_length = max_key_length / cs->mbmaxlen;
7295 24440 local_char_length =
7296
1/2
✓ Branch 0 taken 24440 times.
✗ Branch 1 not taken.
24440 my_charpos(cs, blob1, blob1 + blob_length, local_char_length);
7297 24440 blob_length = min(blob_length, local_char_length);
7298
1/2
✓ Branch 0 taken 24440 times.
✗ Branch 1 not taken.
24440 return Field_blob::cmp(blob1, blob_length, key_ptr + HA_KEY_BLOB_LENGTH,
7299 73320 uint2korr(key_ptr));
7300 }
7301
7302 942 int Field_blob::key_cmp(const uchar *a, const uchar *b) const {
7303 942 return Field_blob::cmp(a + HA_KEY_BLOB_LENGTH, uint2korr(a),
7304 1884 b + HA_KEY_BLOB_LENGTH, uint2korr(b));
7305 }
7306
7307 /**
7308 Save the field metadata for blob fields.
7309
7310 Saves the pack length in the first byte of the field metadata array
7311 at index of *metadata_ptr.
7312
7313 @param metadata_ptr First byte of field metadata
7314
7315 @returns number of bytes written to metadata_ptr
7316 */
7317 1296588 int Field_blob::do_save_field_metadata(uchar *metadata_ptr) const {
7318
1/2
✓ Branch 0 taken 1296656 times.
✗ Branch 1 not taken.
1296588 DBUG_TRACE;
7319 1296656 *metadata_ptr = pack_length_no_ptr();
7320
5/8
✓ Branch 0 taken 1296646 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1296627 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 29 times.
✓ Branch 5 taken 1296598 times.
✓ Branch 6 taken 29 times.
✗ Branch 7 not taken.
1296655 DBUG_PRINT("debug", ("metadata: %u (pack_length_no_ptr)", *metadata_ptr));
7321 1296655 return 1;
7322 1296627 }
7323
7324 3044 size_t Field_blob::make_sort_key(uchar *to, size_t length) const {
7325 static const uchar EMPTY_BLOB[1] = {0};
7326 3044 uint32 blob_length = get_length();
7327
7328 3044 const int flags =
7329
2/2
✓ Branch 0 taken 2852 times.
✓ Branch 1 taken 192 times.
3044 (field_charset->pad_attribute == NO_PAD) ? 0 : MY_STRXFRM_PAD_TO_MAXLEN;
7330
7331
2/2
✓ Branch 0 taken 3031 times.
✓ Branch 1 taken 13 times.
3044 const uchar *blob = blob_length > 0 ? get_blob_data() : EMPTY_BLOB;
7332
7333 3044 return field_charset->coll->strnxfrm(field_charset, to, length, length, blob,
7334 3044 blob_length, flags);
7335 }
7336
7337 987691 void Field_blob::sql_type(String &res) const {
7338 const char *str;
7339 uint length;
7340
4/4
✓ Branch 0 taken 9056 times.
✓ Branch 1 taken 404304 times.
✓ Branch 2 taken 313038 times.
✓ Branch 3 taken 261293 times.
987691 switch (packlength) {
7341 9056 default:
7342 9056 str = "tiny";
7343 9056 length = 4;
7344 9056 break;
7345 404304 case 2:
7346 404304 str = "";
7347 404304 length = 0;
7348 404304 break;
7349 313038 case 3:
7350 313038 str = "medium";
7351 313038 length = 6;
7352 313038 break;
7353 261293 case 4:
7354 261293 str = "long";
7355 261293 length = 4;
7356 261293 break;
7357 }
7358 987691 res.set_ascii(str, length);
7359
2/2
✓ Branch 0 taken 224513 times.
✓ Branch 1 taken 763180 times.
987693 if (charset() == &my_charset_bin)
7360 224513 res.append(STRING_WITH_LEN("blob"));
7361 else {
7362 763180 res.append(STRING_WITH_LEN("text"));
7363 }
7364 987692 }
7365
7366 bool Field_blob::copy() {
7367 const uint32 length = get_length();
7368 if (value.copy(pointer_cast<const char *>(get_blob_data()), length,
7369 charset())) {
7370 Field_blob::reset();
7371 my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), length);
7372 return true;
7373 }
7374 assert(value.length() == length);
7375 set_ptr(length, pointer_cast<const uchar *>(value.ptr()));
7376 return false;
7377 }
7378
7379 810109 uchar *Field_blob::pack(uchar *to, const uchar *from, size_t max_length) const {
7380
1/2
✓ Branch 0 taken 810109 times.
✗ Branch 1 not taken.
810109 uint32 length = get_length(from); // Length of from string
7381
7382 /*
7383 Store max length, which will occupy packlength bytes.
7384 */
7385 uchar len_buf[4];
7386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 810109 times.
810109 assert(packlength <= sizeof(len_buf));
7387
1/2
✓ Branch 0 taken 810109 times.
✗ Branch 1 not taken.
810109 store_blob_length(len_buf, packlength, length);
7388
7389
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 810109 times.
810109 if (packlength >= max_length) {
7390 memcpy(to, len_buf, max_length);
7391 return to + max_length;
7392 }
7393
7394 810109 memcpy(to, len_buf, packlength);
7395
7396 /*
7397 Store the actual blob data, which will occupy 'length' bytes.
7398 */
7399 810109 size_t store_length = min<size_t>(length, max_length - packlength);
7400
2/2
✓ Branch 0 taken 801500 times.
✓ Branch 1 taken 8609 times.
810109 if (store_length > 0) {
7401 801500 memcpy(to + packlength, get_blob_data(from + packlength), store_length);
7402 }
7403
7404 810109 return to + packlength + store_length;
7405 }
7406
7407 6055026 uchar *Field_blob::pack_with_metadata_bytes(uchar *to, const uchar *from,
7408 uint max_length) const {
7409
1/2
✓ Branch 0 taken 6055043 times.
✗ Branch 1 not taken.
6055026 uint32 length = get_length(from); // Length of from string
7410
7411 /*
7412 Store max length, which will occupy packlength bytes. If the max
7413 length given is smaller than the actual length of the blob, we
7414 just store the initial bytes of the blob.
7415 */
7416
1/2
✓ Branch 0 taken 6055009 times.
✗ Branch 1 not taken.
6055043 store_blob_length(to, packlength, min(length, max_length));
7417
7418 /*
7419 Store the actual blob data, which will occupy 'length' bytes.
7420 */
7421
2/2
✓ Branch 0 taken 6026477 times.
✓ Branch 1 taken 28532 times.
6055009 if (length > 0) {
7422 6026477 memcpy(to + packlength, get_blob_data(from + packlength), length);
7423 }
7424 6054991 return to + packlength + length;
7425 }
7426
7427 /**
7428 Unpack a blob field from row data.
7429
7430 This method is used to unpack a blob field from a master whose size of
7431 the field is less than that of the slave. Note: This method is included
7432 to satisfy inheritance rules, but is not needed for blob fields. It
7433 simply is used as a pass-through to the original unpack() method for
7434 blob fields.
7435
7436 @param from Source of the data
7437 @param param_data The "metadata", as stored in the Table_map_log_event
7438 for this field. This metadata is the number of bytes
7439 used to represent the length of the blob (1, 2, 3, or
7440 4).
7441
7442 @return New pointer into memory based on from + length of the data
7443 */
7444 5145113 const uchar *Field_blob::unpack(uchar *, const uchar *from, uint param_data) {
7445
1/2
✓ Branch 0 taken 5145117 times.
✗ Branch 1 not taken.
5145113 DBUG_TRACE;
7446
3/8
✓ Branch 0 taken 5145113 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5145117 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5145117 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
5145117 DBUG_PRINT("enter", ("from: %p;"
7447 " param_data: %u; ",
7448 from, param_data));
7449 5145117 uint const master_packlength =
7450
2/2
✓ Branch 0 taken 149327 times.
✓ Branch 1 taken 4995790 times.
5145117 param_data > 0 ? param_data & 0xFF : packlength;
7451
1/2
✓ Branch 0 taken 5145115 times.
✗ Branch 1 not taken.
5145117 uint32 const length = get_length(from, master_packlength);
7452
1/2
✓ Branch 0 taken 5145116 times.
✗ Branch 1 not taken.
5145115 DBUG_DUMP("packed", from, length + master_packlength);
7453 5145116 bitmap_set_bit(table->write_set, field_index());
7454
1/2
✓ Branch 0 taken 5145117 times.
✗ Branch 1 not taken.
5145114 Field_blob::store(pointer_cast<const char *>(from) + master_packlength,
7455 length, field_charset);
7456
1/2
✓ Branch 0 taken 5145117 times.
✗ Branch 1 not taken.
5145117 DBUG_DUMP("field", ptr, pack_length() /* len bytes + ptr bytes */);
7457
2/4
✓ Branch 0 taken 5145117 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5145117 times.
✗ Branch 3 not taken.
5145117 DBUG_DUMP("value", get_blob_data(), length /* the blob value length */);
7458 5145117 return from + master_packlength + length;
7459 5145117 }
7460
7461 321320 uint Field_blob::max_packed_col_length() const {
7462
2/3
✓ Branch 0 taken 185645 times.
✓ Branch 1 taken 135675 times.
✗ Branch 2 not taken.
321320 switch (packlength) {
7463 185645 case 1:
7464 case 2:
7465 case 3:
7466 185645 return packlength + (1u << (packlength * 8)) - 1;
7467 135675 case 4:
7468 135675 return UINT_MAX;
7469 default:
7470 assert(false);
7471 return UINT_MAX;
7472 }
7473 }
7474
7475 98190 uint Field_blob::is_equal(const Create_field *new_field) const {
7476
1/2
✓ Branch 0 taken 98190 times.
✗ Branch 1 not taken.
98190 DBUG_TRACE;
7477
7478 // Can't use change_prevents_inplace() here as it uses
7479 // sql_type_prevents_inplace() which checks real_type(), and
7480 // Field_blob::real_type() does NOT return the actual blob type as
7481 // one could expect, so we have to check against
7482 // get_blob_type_from_length(max_data_length() instead.
7483 // length_prevents_inplace() is less strict than pack_length
7484 // equality so would be redundant here.
7485
1/2
✓ Branch 0 taken 98190 times.
✗ Branch 1 not taken.
98190 if (new_field->sql_type != get_blob_type_from_length(max_data_length()) ||
7486
2/4
✓ Branch 0 taken 98040 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 98040 times.
✗ Branch 3 not taken.
98040 new_field->pack_length() != pack_length() ||
7487
9/10
✓ Branch 0 taken 98040 times.
✓ Branch 1 taken 150 times.
✓ Branch 2 taken 98040 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 98032 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 32 times.
✓ Branch 7 taken 98000 times.
✓ Branch 8 taken 190 times.
✓ Branch 9 taken 98000 times.
294262 charset_prevents_inplace(*this, *new_field) ||
7488 98032 has_different_compression_attributes_with(*new_field)) {
7489 190 return IS_EQUAL_NO;
7490 }
7491
7492
2/2
✓ Branch 0 taken 97968 times.
✓ Branch 1 taken 32 times.
98000 if (new_field->charset == field_charset) {
7493 97968 return IS_EQUAL_YES;
7494 }
7495
7496 32 return IS_EQUAL_PACK_LENGTH;
7497 98190 }
7498
7499 2845 void Field_geom::sql_type(String &res) const {
7500 2845 const CHARSET_INFO *cs = &my_charset_latin1;
7501
8/8
✓ Branch 0 taken 965 times.
✓ Branch 1 taken 193 times.
✓ Branch 2 taken 161 times.
✓ Branch 3 taken 114 times.
✓ Branch 4 taken 95 times.
✓ Branch 5 taken 91 times.
✓ Branch 6 taken 85 times.
✓ Branch 7 taken 1141 times.
2845 switch (geom_type) {
7502 965 case GEOM_POINT:
7503 965 res.set(STRING_WITH_LEN("point"), cs);
7504 965 break;
7505 193 case GEOM_LINESTRING:
7506 193 res.set(STRING_WITH_LEN("linestring"), cs);
7507 193 break;
7508 161 case GEOM_POLYGON:
7509 161 res.set(STRING_WITH_LEN("polygon"), cs);
7510 161 break;
7511 114 case GEOM_MULTIPOINT:
7512 114 res.set(STRING_WITH_LEN("multipoint"), cs);
7513 114 break;
7514 95 case GEOM_MULTILINESTRING:
7515 95 res.set(STRING_WITH_LEN("multilinestring"), cs);
7516 95 break;
7517 91 case GEOM_MULTIPOLYGON:
7518 91 res.set(STRING_WITH_LEN("multipolygon"), cs);
7519 91 break;
7520 85 case GEOM_GEOMETRYCOLLECTION:
7521 85 res.set(STRING_WITH_LEN("geomcollection"), cs);
7522 85 break;
7523 1141 default:
7524 1141 res.set(STRING_WITH_LEN("geometry"), cs);
7525 }
7526 2845 }
7527
7528 type_conversion_status Field_geom::store(double) {
7529 my_error(ER_CANT_CREATE_GEOMETRY_OBJECT, MYF(0));
7530 return TYPE_ERR_BAD_VALUE;
7531 }
7532
7533 5 type_conversion_status Field_geom::store(longlong, bool) {
7534 5 my_error(ER_CANT_CREATE_GEOMETRY_OBJECT, MYF(0));
7535 5 return TYPE_ERR_BAD_VALUE;
7536 }
7537
7538 2 type_conversion_status Field_geom::store_decimal(const my_decimal *) {
7539 2 my_error(ER_CANT_CREATE_GEOMETRY_OBJECT, MYF(0));
7540 2 return TYPE_ERR_BAD_VALUE;
7541 }
7542
7543 2659637 type_conversion_status Field_geom::store(const char *from, size_t length,
7544 const CHARSET_INFO *cs) {
7545
2/2
✓ Branch 0 taken 386 times.
✓ Branch 1 taken 2659251 times.
2659637 if (length < SRID_SIZE + WKB_HEADER_SIZE + sizeof(uint32)) {
7546 386 Field_blob::reset();
7547 386 my_error(ER_CANT_CREATE_GEOMETRY_OBJECT, MYF(0));
7548 386 return TYPE_ERR_BAD_VALUE;
7549 }
7550
7551 2659251 return Field_blob::store(from, length, cs);
7552 }
7553
7554 2681737 type_conversion_status Field_geom::store_internal(const char *from,
7555 size_t length,
7556 const CHARSET_INFO *cs) {
7557 // Check that the given WKB
7558 // 1. is at least 13 bytes long (length of GEOMETRYCOLLECTION EMPTY)
7559 // 2. isn't marked as bad geometry data
7560 // 3. isn't shorter than empty geometrycollection
7561 // 4. is a valid geometry type
7562 // 5. is well formed
7563
1/2
✓ Branch 0 taken 2681746 times.
✗ Branch 1 not taken.
2681743 if (length < 13 || // 1
7564
1/2
✓ Branch 0 taken 2681746 times.
✗ Branch 1 not taken.
5363484 from == Geometry::bad_geometry_data.ptr() || // 2
7565 2681751 length < SRID_SIZE + WKB_HEADER_SIZE + sizeof(uint32) || // 3
7566
5/6
✓ Branch 0 taken 2681738 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2681468 times.
✓ Branch 3 taken 283 times.
✓ Branch 4 taken 421 times.
✓ Branch 5 taken 2681344 times.
8044966 !Geometry::is_valid_geotype(uint4korr(from + SRID_SIZE + 1)) || // 4
7567
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 2681344 times.
2681468 !Geometry::is_well_formed(from, length, // 5
7568 geometry_type_to_wkb_type(geom_type),
7569 Geometry::wkb_ndr)) {
7570 421 Field_blob::reset();
7571 421 my_error(ER_CANT_CREATE_GEOMETRY_OBJECT, MYF(0));
7572 421 return TYPE_ERR_BAD_VALUE;
7573 }
7574
7575 /*
7576 Check that the SRID of the geometry matches the expected SRID for this
7577 field
7578 */
7579
2/2
✓ Branch 0 taken 1830506 times.
✓ Branch 1 taken 850839 times.
2681344 if (get_srid().has_value()) {
7580 1830506 gis::srid_t geometry_srid = uint4korr(from);
7581
3/4
✓ Branch 0 taken 1830498 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 1830487 times.
1830507 if (geometry_srid != get_srid().value()) {
7582 11 Field_blob::reset();
7583 11 my_error(ER_WRONG_SRID_FOR_COLUMN, MYF(0), field_name,
7584 static_cast<unsigned long>(geometry_srid),
7585
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 static_cast<unsigned long>(get_srid().value()));
7586 11 return TYPE_ERR_BAD_VALUE;
7587 }
7588 }
7589
7590
4/4
✓ Branch 0 taken 1850956 times.
✓ Branch 1 taken 830370 times.
✓ Branch 2 taken 1850894 times.
✓ Branch 3 taken 62 times.
2681326 if (table->copy_blobs || length <= MAX_FIELD_WIDTH) { // Must make a copy
7591 2681264 value.copy(from, length, cs);
7592 2681269 from = value.ptr();
7593 }
7594
7595 2681335 store_ptr_and_length(from, length);
7596 2681335 return TYPE_OK;
7597 }
7598
7599 661 uint Field_geom::is_equal(const Create_field *new_field) const {
7600 661 return new_field->sql_type == real_type() &&
7601
2/2
✓ Branch 0 taken 641 times.
✓ Branch 1 taken 15 times.
656 new_field->geom_type == get_geometry_type() &&
7602
3/4
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 641 times.
✗ Branch 3 not taken.
1958 new_field->charset == field_charset &&
7603
1/2
✓ Branch 0 taken 641 times.
✗ Branch 1 not taken.
1302 new_field->pack_length() == pack_length();
7604 }
7605
7606 /**
7607 Get the type of this field (json).
7608 @param str the string that receives the type
7609 */
7610 111360 void Field_json::sql_type(String &str) const {
7611 111360 str.set_ascii(STRING_WITH_LEN("json"));
7612 111360 }
7613
7614 /// Create a shallow clone of this field in the specified MEM_ROOT.
7615 923832 Field_json *Field_json::clone(MEM_ROOT *mem_root) const {
7616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 923833 times.
923832 assert(type() == MYSQL_TYPE_JSON);
7617
1/2
✓ Branch 0 taken 923834 times.
✗ Branch 1 not taken.
923833 return new (mem_root) Field_json(*this);
7618 }
7619
7620 /**
7621 Check if a new field is compatible with this one.
7622 @param new_field the new field
7623 @return true if new_field is compatible with this field, false otherwise
7624 */
7625 5569 uint Field_json::is_equal(const Create_field *new_field) const {
7626 // All JSON fields are compatible with each other.
7627
2/2
✓ Branch 0 taken 5563 times.
✓ Branch 1 taken 6 times.
11132 return (new_field->sql_type == real_type() &&
7628
2/2
✓ Branch 0 taken 5558 times.
✓ Branch 1 taken 5 times.
11132 !has_different_compression_attributes_with(*new_field));
7629 }
7630
7631 /**
7632 Store data in this JSON field.
7633
7634 JSON data is usually stored using store(Field_json*) or store_json(), so this
7635 function will only be called if non-JSON data is attempted stored in a JSON
7636 field. This results in an error in most cases.
7637
7638 It will attempt to parse the string (unless it's binary) as JSON text, and
7639 store a binary representation of JSON document if the string could be parsed.
7640
7641 Note that we override store() and not store_internal() because
7642 Field_blob::store() contains logic that bypasses store_internal() in
7643 some cases we care about. In particular:
7644
7645 - When supplied an empty string, we want to raise a JSON syntax
7646 error instead of silently inserting an empty byte string.
7647
7648 - When called from GROUP_CONCAT with ORDER BY or DISTINCT, we want
7649 to do the same data conversion as usual, whereas
7650 Field_blob::store() jumps directly to Field_blob::store_to_mem()
7651 with the unprocessed input data.
7652
7653 @param from the start of the data to be stored
7654 @param length the length of the data
7655 @param cs the character set of the data
7656 @return zero on success, non-zero on failure
7657 */
7658 41670 type_conversion_status Field_json::store(const char *from, size_t length,
7659 const CHARSET_INFO *cs) {
7660
3/6
✓ Branch 0 taken 41675 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41679 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 41683 times.
41670 ASSERT_COLUMN_MARKED_FOR_WRITE;
7661
7662 /*
7663 First clear the field so that it doesn't contain garbage if we
7664 return with an error. Some callers continue for a while even after
7665 an error has been raised, and they could get into trouble if the
7666 field contains garbage.
7667 */
7668
1/2
✓ Branch 0 taken 41688 times.
✗ Branch 1 not taken.
41674 reset();
7669
7670 const char *s;
7671 size_t ss;
7672 41688 String v(from, length, cs);
7673
7674
3/4
✓ Branch 0 taken 41682 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 41680 times.
41690 if (ensure_utf8mb4(v, &value, &s, &ss, true)) {
7675 2 return TYPE_ERR_BAD_VALUE;
7676 }
7677
7678 41680 const char *err_table_name = *table_name;
7679 41680 const char *err_field_name = field_name;
7680 std::unique_ptr<Json_dom> dom(Json_dom::parse(
7681 s, ss,
7682 31 [err_table_name, err_field_name](const char *parse_err,
7683 62 size_t err_offset) {
7684 31 String s_err;
7685
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 s_err.append(err_table_name);
7686
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 s_err.append('.');
7687
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 s_err.append(err_field_name);
7688
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
31 my_error(ER_INVALID_JSON_TEXT, MYF(0), parse_err, err_offset,
7689 s_err.c_ptr_safe());
7690 31 },
7691
1/2
✓ Branch 0 taken 41671 times.
✗ Branch 1 not taken.
83365 JsonDocumentDefaultDepthHandler));
7692
7693
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 41661 times.
41693 if (dom.get() == nullptr) return TYPE_ERR_BAD_VALUE;
7694
7695
4/6
✓ Branch 0 taken 41654 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41646 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 41645 times.
41661 if (json_binary::serialize(current_thd, dom.get(), &value))
7696 1 return TYPE_ERR_BAD_VALUE;
7697
7698
1/2
✓ Branch 0 taken 41629 times.
✗ Branch 1 not taken.
41645 return store_binary(value.ptr(), value.length());
7699 41663 }
7700
7701 /**
7702 Helper function for raising an error when trying to store a value
7703 into a JSON column, and that value needs to be cast to JSON before
7704 it can be stored.
7705 */
7706 18 type_conversion_status Field_json::unsupported_conversion() {
7707
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
18 ASSERT_COLUMN_MARKED_FOR_WRITE;
7708 18 String s;
7709
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 s.append(*table_name);
7710
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 s.append('.');
7711
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 s.append(field_name);
7712
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 my_error(ER_INVALID_JSON_TEXT, MYF(0), "not a JSON text, may need CAST", 0,
7713 s.c_ptr_safe());
7714 18 return TYPE_ERR_BAD_VALUE;
7715 18 }
7716
7717 /**
7718 Store the provided JSON binary data in this field.
7719
7720 @param[in] data pointer to JSON binary data
7721 @param[in] length the length of the binary data
7722 @return zero on success, non-zero on failure
7723 */
7724 312328 type_conversion_status Field_json::store_binary(const char *data,
7725 size_t length) {
7726 /*
7727 We expect that a valid binary representation of a JSON document is
7728 passed to us.
7729 */
7730
2/4
✓ Branch 0 taken 312360 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 312360 times.
312328 assert(json_binary::parse_binary(data, length).is_valid());
7731
7732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 312360 times.
312360 if (length > UINT_MAX32) {
7733 /* purecov: begin inspected */
7734 my_error(ER_JSON_VALUE_TOO_BIG, MYF(0));
7735 return TYPE_ERR_BAD_VALUE;
7736 /* purecov: end */
7737 }
7738
7739 312360 return Field_blob::store(data, length, field_charset);
7740 }
7741
7742 /// Store a double in a JSON field. Will raise an error for now.
7743 4 type_conversion_status Field_json::store(double) {
7744 4 return unsupported_conversion();
7745 }
7746
7747 /// Store an integer in a JSON field. Will raise an error for now.
7748 8 type_conversion_status Field_json::store(longlong, bool) {
7749 8 return unsupported_conversion();
7750 }
7751
7752 /// Store a decimal in a JSON field. Will raise an error for now.
7753 3 type_conversion_status Field_json::store_decimal(const my_decimal *) {
7754 3 return unsupported_conversion();
7755 }
7756
7757 /// Store a TIME value in a JSON field. Will raise an error for now.
7758 3 type_conversion_status Field_json::store_time(MYSQL_TIME *, uint8) {
7759 3 return unsupported_conversion();
7760 }
7761
7762 /**
7763 Store a JSON value as binary.
7764
7765 @param json the JSON value to store
7766 @return zero on success, non-zero otherwise
7767 */
7768 54005 type_conversion_status Field_json::store_json(const Json_wrapper *json) {
7769
4/6
✓ Branch 0 taken 54005 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54002 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 54002 times.
54005 ASSERT_COLUMN_MARKED_FOR_WRITE;
7770
7771 /*
7772 We want to serialize the JSON value directly into Field_blob::value if
7773 possible, so that we don't have to copy it there afterwards.
7774
7775 If the Json_wrapper is pointing to a document that already lives in
7776 Field_blob::value, it isn't safe to do so, since the source buffer and
7777 destination buffer is the same. This can happen if an UPDATE statement
7778 updates the same JSON column twice and the second update of the column
7779 reads data that the first update wrote to the output buffer. For example:
7780
7781 UPDATE t SET json_col = <something>, json_col = json_col->'$.path'
7782
7783 In that case, we serialize into a temporary string, which is later copied
7784 into Field_blob::value by store_binary().
7785 */
7786 54005 StringBuffer<STRING_BUFFER_USUAL_SIZE> tmpstr;
7787
3/4
✓ Branch 0 taken 54005 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71 times.
✓ Branch 3 taken 53934 times.
54005 String *buffer = json->is_binary_backed_by(&value) ? &tmpstr : &value;
7788
7789
4/6
✓ Branch 0 taken 54005 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54005 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 53999 times.
54005 if (json->to_binary(current_thd, buffer)) return TYPE_ERR_BAD_VALUE;
7790
7791
1/2
✓ Branch 0 taken 53999 times.
✗ Branch 1 not taken.
53999 return store_binary(buffer->ptr(), buffer->length());
7792 54005 }
7793
7794 /**
7795 Copy the contents of a non-null JSON field into this field.
7796
7797 @param[in] field the field to copy data from
7798 @return zero on success, non-zero on failure
7799 */
7800 216706 type_conversion_status Field_json::store(const Field_json *field) {
7801 /*
7802 The callers of this function have already checked for null, so we
7803 don't need to handle it here for now. Assert that field is not
7804 null.
7805 */
7806
2/4
✓ Branch 0 taken 216706 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 216706 times.
216706 assert(!field->is_null());
7807
7808 216706 String tmp;
7809
1/2
✓ Branch 0 taken 216706 times.
✗ Branch 1 not taken.
216706 String *s = field->Field_blob::val_str(&tmp, &tmp);
7810
1/2
✓ Branch 0 taken 216706 times.
✗ Branch 1 not taken.
433412 return store_binary(s->ptr(), s->length());
7811 216706 }
7812
7813 709741 bool Field_json::val_json(Json_wrapper *wr) const {
7814
1/2
✓ Branch 0 taken 709784 times.
✗ Branch 1 not taken.
709741 DBUG_TRACE;
7815
4/6
✓ Branch 0 taken 709785 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 709775 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 709772 times.
709784 ASSERT_COLUMN_MARKED_FOR_READ;
7816
7817 709781 String tmp;
7818
1/2
✓ Branch 0 taken 709776 times.
✗ Branch 1 not taken.
709782 String *s = Field_blob::val_str(&tmp, &tmp);
7819
7820
1/2
✓ Branch 0 taken 709786 times.
✗ Branch 1 not taken.
709776 json_binary::Value v(json_binary::parse_binary(s->ptr(), s->length()));
7821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 709753 times.
709786 if (v.type() == json_binary::Value::ERROR) {
7822 /* purecov: begin inspected */
7823 my_error(ER_INVALID_JSON_BINARY_DATA, MYF(0));
7824 return true;
7825 /* purecov: end */
7826 }
7827
7828
1/2
✓ Branch 0 taken 709750 times.
✗ Branch 1 not taken.
709753 *wr = Json_wrapper(v);
7829 709765 return false;
7830 709765 }
7831
7832 431 longlong Field_json::val_int() const {
7833
3/6
✓ Branch 0 taken 431 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 431 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 431 times.
431 ASSERT_COLUMN_MARKED_FOR_READ;
7834
7835 431 Json_wrapper wr;
7836
2/4
✓ Branch 0 taken 431 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 431 times.
431 if (val_json(&wr)) return 0; /* purecov: inspected */
7837
7838
1/2
✓ Branch 0 taken 431 times.
✗ Branch 1 not taken.
431 return wr.coerce_int(field_name);
7839 431 }
7840
7841 589 double Field_json::val_real() const {
7842
3/6
✓ Branch 0 taken 589 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 589 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 589 times.
589 ASSERT_COLUMN_MARKED_FOR_READ;
7843
7844 589 Json_wrapper wr;
7845
2/4
✓ Branch 0 taken 589 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 589 times.
589 if (val_json(&wr)) return 0.0; /* purecov: inspected */
7846
7847
1/2
✓ Branch 0 taken 589 times.
✗ Branch 1 not taken.
589 return wr.coerce_real(field_name);
7848 589 }
7849
7850 191811 String *Field_json::val_str(String *buf1, String *) const {
7851
4/6
✓ Branch 0 taken 191811 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 191806 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 191806 times.
191811 ASSERT_COLUMN_MARKED_FOR_READ;
7852
7853 /*
7854 Per contract of Field::val_str(String*,String*), buf1 should be
7855 used if the value needs to be converted to string, and buf2 should
7856 be used if the string value is already known. We need to convert,
7857 so use buf1.
7858 */
7859 191811 buf1->length(0);
7860
7861 191811 Json_wrapper wr;
7862
2/4
✓ Branch 0 taken 191811 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 191811 times.
✗ Branch 3 not taken.
383622 if (val_json(&wr) ||
7863
6/10
✓ Branch 0 taken 191811 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 191808 times.
✓ Branch 4 taken 191811 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 191808 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
383622 wr.to_string(buf1, true, field_name, JsonDocumentDefaultDepthHandler))
7864 3 buf1->length(0);
7865
7866 191811 return buf1;
7867 191811 }
7868
7869 64 my_decimal *Field_json::val_decimal(my_decimal *decimal_value) const {
7870
3/6
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 64 times.
64 ASSERT_COLUMN_MARKED_FOR_READ;
7871
7872 64 Json_wrapper wr;
7873
2/4
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 64 times.
64 if (val_json(&wr)) {
7874 /* purecov: begin inspected */
7875 my_decimal_set_zero(decimal_value);
7876 return decimal_value;
7877 /* purecov: end */
7878 }
7879
7880
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 return wr.coerce_decimal(decimal_value, field_name);
7881 64 }
7882
7883 11458 bool Field_json::pack_diff(uchar **to, ulonglong value_format) const {
7884
1/2
✓ Branch 0 taken 11458 times.
✗ Branch 1 not taken.
11458 DBUG_TRACE;
7885
7886 const Json_diff_vector *diff_vector;
7887
1/2
✓ Branch 0 taken 11458 times.
✗ Branch 1 not taken.
11458 get_diff_vector_and_length(value_format, &diff_vector);
7888
2/2
✓ Branch 0 taken 8489 times.
✓ Branch 1 taken 2969 times.
11458 if (diff_vector == nullptr) return true;
7889
7890 // We know the caller has allocated enough space, but we don't
7891 // know how much it is. So just say that it is large, to
7892 // suppress bounds checks.
7893 2969 String to_string((char *)*to, 0xffffFFFF, &my_charset_bin);
7894 2969 to_string.length(0);
7895
2/4
✓ Branch 0 taken 2969 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2969 times.
2969 if (diff_vector->write_binary(&to_string))
7896 // write_binary only returns true (error) in case it failed to
7897 // allocate memory. But now we know it will not try to
7898 // allocate.
7899 assert(0); /* purecov: inspected */
7900
7901 // It should not have reallocated.
7902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2969 times.
2969 assert(*to == (uchar *)to_string.ptr());
7903
7904 2969 *to += to_string.length();
7905 2969 return false;
7906 11458 }
7907
7908 11785 bool Field_json::is_before_image_equal_to_after_image() const {
7909 11785 ptrdiff_t row_offset = table->record[1] - table->record[0];
7910
2/2
✓ Branch 0 taken 4381 times.
✓ Branch 1 taken 7404 times.
11785 if (get_length(row_offset) != get_length()) return false;
7911
2/2
✓ Branch 0 taken 4146 times.
✓ Branch 1 taken 3258 times.
7404 if (cmp(ptr, ptr + row_offset) != 0) return false;
7912 3258 return true;
7913 }
7914
7915 24113 longlong Field_json::get_diff_vector_and_length(
7916 ulonglong value_options, const Json_diff_vector **diff_vector_p) const {
7917
1/2
✓ Branch 0 taken 24113 times.
✗ Branch 1 not taken.
24113 DBUG_TRACE;
7918
7919
3/4
✓ Branch 0 taken 24113 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3613 times.
✓ Branch 3 taken 20500 times.
24113 if (is_null()) {
7920
3/8
✓ Branch 0 taken 3613 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3613 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3613 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3613 DBUG_PRINT("info", ("Returning 0 because field is NULL"));
7921
2/2
✓ Branch 0 taken 486 times.
✓ Branch 1 taken 3127 times.
3613 if (diff_vector_p) *diff_vector_p = nullptr;
7922 3613 return 0;
7923 }
7924
7925
1/2
✓ Branch 0 taken 20500 times.
✗ Branch 1 not taken.
20500 longlong length_of_full_format = get_length();
7926 20500 longlong length = -1;
7927 20500 const Json_diff_vector *diff_vector = nullptr;
7928 // Is the partial update smaller than the full update?
7929
3/8
✓ Branch 0 taken 20500 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20500 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 20500 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
20500 DBUG_PRINT("info", ("length_of_full_format=%lu",
7930 (unsigned long)length_of_full_format));
7931
7932 // Is partial JSON updates enabled at all?
7933
2/2
✓ Branch 0 taken 7239 times.
✓ Branch 1 taken 13261 times.
20500 if ((value_options & PARTIAL_JSON_UPDATES) == 0) {
7934
3/8
✓ Branch 0 taken 7239 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7239 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7239 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
7239 DBUG_PRINT("info", ("Using full JSON format because "
7935 "binlog_row_value_format does not include "
7936 "PARTIAL_JSON"));
7937 7239 length = length_of_full_format;
7938 } else {
7939 // Was the optimizer able to compute a partial update?
7940
1/2
✓ Branch 0 taken 13261 times.
✗ Branch 1 not taken.
13261 diff_vector = table->get_logical_diffs(this);
7941
2/2
✓ Branch 0 taken 6571 times.
✓ Branch 1 taken 6690 times.
13261 if (diff_vector == nullptr) {
7942 // Are before-image and after-image equal?
7943
3/4
✓ Branch 0 taken 6571 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3173 times.
✓ Branch 3 taken 3398 times.
6571 if (is_before_image_equal_to_after_image()) {
7944
3/8
✓ Branch 0 taken 3173 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3173 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3173 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3173 DBUG_PRINT("info", ("Using empty Json_diff_vector because before-image "
7945 "is different from after-image."));
7946 3173 diff_vector = &Json_diff_vector::EMPTY_JSON_DIFF_VECTOR;
7947
1/2
✓ Branch 0 taken 3173 times.
✗ Branch 1 not taken.
3173 length = diff_vector->binary_length();
7948 } else {
7949
3/8
✓ Branch 0 taken 3398 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3398 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3398 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3398 DBUG_PRINT("info",
7950 ("Using full JSON format because there is no diff vector "
7951 "and before-image is different from after-image."));
7952 3398 length = length_of_full_format;
7953 }
7954 } else {
7955
1/2
✓ Branch 0 taken 6690 times.
✗ Branch 1 not taken.
6690 longlong length_of_diff_vector = diff_vector->binary_length();
7956 longlong length_of_empty_diff_vector =
7957
1/2
✓ Branch 0 taken 6690 times.
✗ Branch 1 not taken.
6690 Json_diff_vector::EMPTY_JSON_DIFF_VECTOR.binary_length();
7958
3/8
✓ Branch 0 taken 6690 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6690 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6690 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6690 DBUG_PRINT("info", ("length_of_diff_vector=%lu diff_vector->size()=%u",
7959 (unsigned long)length_of_diff_vector,
7960 (uint)diff_vector->size()));
7961
7962 // If the vector is empty, no need to do the expensive comparison
7963 // between before-image and after-image.
7964
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5214 times.
6690 if (length_of_diff_vector == length_of_empty_diff_vector) {
7965
3/8
✓ Branch 0 taken 1476 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1476 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1476 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1476 DBUG_PRINT("info",
7966 ("Using empty Json_diff_vector provided by optimizer."));
7967 1476 length = length_of_diff_vector;
7968 }
7969 // Are the before-image and the after-image equal? (This can
7970 // happen despite having a nonempty diff vector, in case
7971 // optimizer does not detect the equality)
7972
3/4
✓ Branch 0 taken 5214 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 85 times.
✓ Branch 3 taken 5129 times.
5214 else if (is_before_image_equal_to_after_image()) {
7973
3/8
✓ Branch 0 taken 85 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 85 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 85 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
85 DBUG_PRINT("info", ("Using Json_diff_vector::EMPTY_JSON_DIFF_VECTOR "
7974 "because the before-image equals the after-image "
7975 "but the diff vector provided by the optimizer "
7976 "is non-empty."));
7977 85 diff_vector = &Json_diff_vector::EMPTY_JSON_DIFF_VECTOR;
7978 85 length = length_of_diff_vector;
7979 }
7980 // Is the diff vector better than the full format?
7981
2/2
✓ Branch 0 taken 4940 times.
✓ Branch 1 taken 189 times.
5129 else if (length_of_diff_vector < length_of_full_format) {
7982
3/8
✓ Branch 0 taken 4940 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4940 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4940 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
4940 DBUG_PRINT("info", ("Using non-empty Json_diff_vector provided by "
7983 "optimizer because it is smaller than "
7984 "full format."));
7985 4940 length = length_of_diff_vector;
7986 } else {
7987
3/8
✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 189 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
189 DBUG_PRINT("info",
7988 ("Using full JSON format because diff vector was not "
7989 "smaller."));
7990 189 diff_vector = nullptr;
7991 189 length = length_of_full_format;
7992 }
7993 }
7994 }
7995
7996 /*
7997 Can be equal to zero in the corner case where user inserted NULL
7998 value in a JSON NOT NULL column in non-strict mode. The server
7999 will store this as a zero-length non-NULL object, and interpret it
8000 as a JSON 'null' literal.
8001 */
8002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20500 times.
20500 assert(length >= 0);
8003
8004
2/2
✓ Branch 0 taken 14688 times.
✓ Branch 1 taken 5812 times.
20500 if (diff_vector_p != nullptr) *diff_vector_p = diff_vector;
8005 20500 return length;
8006 24113 }
8007
8008 2354 bool Field_json::unpack_diff(const uchar **from) {
8009
1/2
✓ Branch 0 taken 2354 times.
✗ Branch 1 not taken.
2354 DBUG_TRACE;
8010
8011 // Use a temporary mem_root so that the thread does not hold the
8012 // memory for the Json_diff_vector until the end of the statement.
8013 2354 int memory_page_size = my_getpagesize();
8014 MEM_ROOT mem_root(key_memory_Slave_applier_json_diff_vector,
8015 2354 memory_page_size);
8016
8017
1/2
✓ Branch 0 taken 2354 times.
✗ Branch 1 not taken.
2354 Json_diff_vector diff_vector{Json_diff_vector::allocator_type(&mem_root)};
8018
8019 // The caller should have verified that the buffer at 'from' is
8020 // sufficiently big to hold the whole diff_vector.
8021
3/4
✓ Branch 0 taken 2354 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 81 times.
✓ Branch 3 taken 2273 times.
2354 if (diff_vector.read_binary(pointer_cast<const char **>(from), table,
8022 field_name))
8023 81 return true;
8024
8025 // Apply
8026
4/6
✓ Branch 0 taken 2273 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 2237 times.
✗ Branch 5 not taken.
2273 switch (apply_json_diffs(this, &diff_vector)) {
8027 27 case enum_json_diff_status::REJECTED:
8028 27 my_error(ER_COULD_NOT_APPLY_JSON_DIFF, MYF(0),
8029
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 (int)table->s->table_name.length, table->s->table_name.str,
8030 field_name);
8031 27 return true;
8032 9 case enum_json_diff_status::ERROR:
8033 9 return true; /* purecov: inspected */
8034 2237 case enum_json_diff_status::SUCCESS:
8035 2237 break;
8036 }
8037 2237 return false;
8038 2354 }
8039
8040 138 bool Field_json::get_date(MYSQL_TIME *ltime, my_time_flags_t) const {
8041
3/6
✓ Branch 0 taken 138 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 138 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 138 times.
138 ASSERT_COLUMN_MARKED_FOR_READ;
8042
8043 138 Json_wrapper wr;
8044
5/8
✓ Branch 0 taken 138 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 138 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 123 times.
✓ Branch 7 taken 15 times.
138 bool result = val_json(&wr) || wr.coerce_date(ltime, field_name);
8045
2/2
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 15 times.
138 if (result)
8046
1/2
✓ Branch 0 taken 123 times.
✗ Branch 1 not taken.
123 set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME); /* purecov: inspected */
8047 138 return result;
8048 138 }
8049
8050 62 bool Field_json::get_time(MYSQL_TIME *ltime) const {
8051
3/6
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 ASSERT_COLUMN_MARKED_FOR_READ;
8052
8053 62 Json_wrapper wr;
8054
5/8
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 62 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 58 times.
✓ Branch 7 taken 4 times.
62 bool result = val_json(&wr) || wr.coerce_time(ltime, field_name);
8055
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 4 times.
62 if (result)
8056
1/2
✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
58 set_zero_time(ltime, MYSQL_TIMESTAMP_TIME); /* purecov: inspected */
8057 62 return result;
8058 62 }
8059
8060 13720 int Field_json::cmp_binary(const uchar *a_ptr, const uchar *b_ptr,
8061 uint32 /* max_length */) const {
8062 13720 const char *a = pointer_cast<char *>(get_blob_data(a_ptr + packlength));
8063 13720 const char *b = pointer_cast<char *>(get_blob_data(b_ptr + packlength));
8064
1/2
✓ Branch 0 taken 13720 times.
✗ Branch 1 not taken.
13720 uint32 a_length = get_length(a_ptr);
8065
1/2
✓ Branch 0 taken 13720 times.
✗ Branch 1 not taken.
13720 uint32 b_length = get_length(b_ptr);
8066
2/4
✓ Branch 0 taken 13720 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13720 times.
✗ Branch 3 not taken.
13720 Json_wrapper aw(json_binary::parse_binary(a, a_length));
8067
2/4
✓ Branch 0 taken 13720 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13720 times.
✗ Branch 3 not taken.
13720 Json_wrapper bw(json_binary::parse_binary(b, b_length));
8068
1/2
✓ Branch 0 taken 13720 times.
✗ Branch 1 not taken.
27440 return aw.compare(bw);
8069 13720 }
8070
8071 101 size_t Field_json::make_sort_key(uchar *to, size_t length) const {
8072 101 Json_wrapper wr;
8073
2/4
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 101 times.
101 if (val_json(&wr)) {
8074 return 0;
8075 }
8076
1/2
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
101 return wr.make_sort_key(to, length);
8077 101 }
8078
8079 2689 ulonglong Field_json::make_hash_key(ulonglong hash_val) const {
8080 2689 Json_wrapper wr;
8081
2/4
✓ Branch 0 taken 2689 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2689 times.
2689 if (val_json(&wr)) return hash_val; /* purecov: inspected */
8082
1/2
✓ Branch 0 taken 2689 times.
✗ Branch 1 not taken.
2689 return wr.make_hash_key(hash_val);
8083 2689 }
8084
8085 28097 const char *Field_json::get_binary(ptrdiff_t row_offset) const {
8086 28097 return pointer_cast<char *>(get_blob_data(ptr + packlength + row_offset));
8087 }
8088
8089 /****************************************************************************
8090 ** enum type.
8091 ** This is a string which only can have a selection of different values.
8092 ** If one uses this string in a number context one gets the type number.
8093 ****************************************************************************/
8094
8095 219340 enum ha_base_keytype Field_enum::key_type() const {
8096
4/5
✓ Branch 0 taken 219258 times.
✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 3 times.
219340 switch (packlength) {
8097 219258 default:
8098 219258 return HA_KEYTYPE_BINARY;
8099 69 case 2:
8100 69 return HA_KEYTYPE_USHORT_INT;
8101 case 3:
8102 return HA_KEYTYPE_UINT24;
8103 10 case 4:
8104 10 return HA_KEYTYPE_ULONG_INT;
8105 3 case 8:
8106 3 return HA_KEYTYPE_ULONGLONG;
8107 }
8108 }
8109
8110 144007838 void Field_enum::store_type(ulonglong value) {
8111
4/6
✓ Branch 0 taken 143650664 times.
✓ Branch 1 taken 21260 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 221 times.
✓ Branch 4 taken 335693 times.
✗ Branch 5 not taken.
144007838 switch (packlength) {
8112 143650664 case 1:
8113 143650664 ptr[0] = (uchar)value;
8114 143650664 break;
8115 21260 case 2:
8116
1/2
✓ Branch 0 taken 21260 times.
✗ Branch 1 not taken.
21260 if (table->s->db_low_byte_first)
8117 21260 int2store(ptr, (unsigned short)value);
8118 else
8119 shortstore(ptr, (unsigned short)value);
8120 21260 break;
8121 case 3:
8122 int3store(ptr, (long)value);
8123 break;
8124 221 case 4:
8125
1/2
✓ Branch 0 taken 221 times.
✗ Branch 1 not taken.
221 if (table->s->db_low_byte_first)
8126 221 int4store(ptr, value);
8127 else
8128 longstore(ptr, (long)value);
8129 221 break;
8130 335693 case 8:
8131
1/2
✓ Branch 0 taken 335693 times.
✗ Branch 1 not taken.
335693 if (table->s->db_low_byte_first)
8132 335693 int8store(ptr, value);
8133 else
8134 longlongstore(ptr, value);
8135 335693 break;
8136 }
8137 144007838 }
8138
8139 /**
8140 @note
8141 Storing a empty string in a enum field gives a warning
8142 (if there isn't a empty value in the enum)
8143 */
8144
8145 12724946 type_conversion_status Field_enum::store(const char *from, size_t length,
8146 const CHARSET_INFO *cs) {
8147
4/6
✓ Branch 0 taken 12724946 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12464502 times.
✓ Branch 3 taken 260444 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12464502 times.
12724946 ASSERT_COLUMN_MARKED_FOR_WRITE;
8148 12724946 int err = 0;
8149 12724946 type_conversion_status ret = TYPE_OK;
8150 char buff[STRING_BUFFER_USUAL_SIZE];
8151 12724946 String tmpstr(buff, sizeof(buff), &my_charset_bin);
8152
8153 /* Convert character set if necessary */
8154
3/4
✓ Branch 0 taken 12724946 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1704615 times.
✓ Branch 3 taken 11020331 times.
12724946 if (String::needs_conversion_on_storage(length, cs, field_charset)) {
8155 uint dummy_errors;
8156
1/2
✓ Branch 0 taken 1704615 times.
✗ Branch 1 not taken.
1704615 tmpstr.copy(from, length, cs, field_charset, &dummy_errors);
8157 1704615 from = tmpstr.ptr();
8158 1704615 length = tmpstr.length();
8159 }
8160
8161 /* Remove end space */
8162
1/2
✓ Branch 0 taken 12724946 times.
✗ Branch 1 not taken.
12724946 length = field_charset->cset->lengthsp(field_charset, from, length);
8163
1/2
✓ Branch 0 taken 12724946 times.
✗ Branch 1 not taken.
12724946 uint tmp = find_type2(typelib, from, length, field_charset);
8164
2/2
✓ Branch 0 taken 333502 times.
✓ Branch 1 taken 12391444 times.
12724946 if (!tmp) {
8165
2/2
✓ Branch 0 taken 333419 times.
✓ Branch 1 taken 83 times.
333502 if (length < 6) // Can't be more than 99999 enums
8166 {
8167 /* This is for reading numbers with LOAD DATA INFILE */
8168 const char *end;
8169
1/2
✓ Branch 0 taken 333419 times.
✗ Branch 1 not taken.
333419 tmp = (uint)my_strntoul(cs, from, length, 10, &end, &err);
8170
6/6
✓ Branch 0 taken 333371 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 333365 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 333362 times.
333419 if (err || end != from + length || tmp > typelib->count) {
8171 57 tmp = 0;
8172
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
8173 57 ret = TYPE_WARN_TRUNCATED;
8174 }
8175
3/4
✓ Branch 0 taken 333419 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 333212 times.
✓ Branch 3 taken 207 times.
333419 if (!current_thd->check_for_truncated_fields) ret = TYPE_OK;
8176 } else
8177
1/2
✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
83 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
8178 }
8179
1/2
✓ Branch 0 taken 12724946 times.
✗ Branch 1 not taken.
12724946 store_type((ulonglong)tmp);
8180 12724946 return ret;
8181 12724946 }
8182
8183 130 type_conversion_status Field_enum::store(double nr) {
8184
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 129 times.
130 if (nr < LLONG_MIN)
8185 1 return Field_enum::store(static_cast<longlong>(LLONG_MIN), false);
8186
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 128 times.
129 if (nr > LLONG_MAX_DOUBLE)
8187 1 return Field_enum::store(static_cast<longlong>(LLONG_MAX), false);
8188 128 return Field_enum::store(static_cast<longlong>(nr), false);
8189 }
8190
8191 34608940 type_conversion_status Field_enum::store(longlong nr, bool) {
8192
4/6
✓ Branch 0 taken 34608940 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34363073 times.
✓ Branch 3 taken 245867 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 34363074 times.
34608940 ASSERT_COLUMN_MARKED_FOR_WRITE;
8193 34608941 type_conversion_status error = TYPE_OK;
8194
4/4
✓ Branch 0 taken 34608934 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 34608923 times.
34608941 if ((ulonglong)nr > typelib->count || nr == 0) {
8195 18 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
8196
6/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 2 times.
18 if (nr != 0 || current_thd->check_for_truncated_fields) {
8197 16 nr = 0;
8198 16 error = TYPE_WARN_TRUNCATED;
8199 }
8200 }
8201 34608941 store_type((ulonglong)(uint)nr);
8202 34608942 return error;
8203 }
8204
8205 1262 double Field_enum::val_real() const { return (double)Field_enum::val_int(); }
8206
8207 2 my_decimal *Field_enum::val_decimal(my_decimal *decimal_value) const {
8208
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 ASSERT_COLUMN_MARKED_FOR_READ;
8209 2 int2my_decimal(E_DEC_FATAL_ERROR, val_int(), false, decimal_value);
8210 2 return decimal_value;
8211 }
8212
8213 // Utility function used by ::val_int() and ::cmp()
8214 289236321 static longlong enum_val_int(const uchar *ptr, uint packlength,
8215 bool low_byte_first) {
8216
5/6
✓ Branch 0 taken 288480148 times.
✓ Branch 1 taken 52221 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4449 times.
✓ Branch 4 taken 699501 times.
✓ Branch 5 taken 2 times.
289236321 switch (packlength) {
8217 288480148 case 1:
8218 288480148 return ptr[0];
8219 52221 case 2: {
8220
1/2
✓ Branch 0 taken 52221 times.
✗ Branch 1 not taken.
52221 if (low_byte_first)
8221 52221 return uint2korr(ptr);
8222 else
8223 return ushortget(ptr);
8224 }
8225 case 3:
8226 return uint3korr(ptr);
8227 4449 case 4: {
8228
1/2
✓ Branch 0 taken 4449 times.
✗ Branch 1 not taken.
4449 if (low_byte_first)
8229 4449 return uint4korr(ptr);
8230 else
8231 return ulongget(ptr);
8232 }
8233 699501 case 8: {
8234
2/2
✓ Branch 0 taken 699499 times.
✓ Branch 1 taken 2 times.
699501 if (low_byte_first)
8235 699499 return sint8korr(ptr);
8236 else
8237 2 return longlongget(ptr);
8238 }
8239 }
8240 2 return 0; // impossible
8241 }
8242
8243 289117639 longlong Field_enum::val_int() const {
8244
4/6
✓ Branch 0 taken 289117641 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 288844917 times.
✓ Branch 3 taken 272724 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 288844919 times.
289117639 ASSERT_COLUMN_MARKED_FOR_READ;
8245 289117641 return enum_val_int(ptr, packlength, table->s->db_low_byte_first);
8246 }
8247
8248 /**
8249 Save the field metadata for enum fields.
8250
8251 Saves the real type in the first byte and the pack length in the
8252 second byte of the field metadata array at index of *metadata_ptr and
8253 *(metadata_ptr + 1).
8254
8255 @param metadata_ptr First byte of field metadata
8256
8257 @returns number of bytes written to metadata_ptr
8258 */
8259 31880 int Field_enum::do_save_field_metadata(uchar *metadata_ptr) const {
8260 31880 *metadata_ptr = real_type();
8261 31880 *(metadata_ptr + 1) = pack_length();
8262 31880 return 2;
8263 }
8264
8265 101479446 String *Field_enum::val_str(String *, String *val_ptr) const {
8266 101479446 uint tmp = (uint)Field_enum::val_int();
8267
3/4
✓ Branch 0 taken 101395038 times.
✓ Branch 1 taken 84408 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 101395038 times.
101479446 if (!tmp || tmp > typelib->count)
8268 84408 val_ptr->set("", 0, field_charset);
8269 else
8270 101395038 val_ptr->set(typelib->type_names[tmp - 1], typelib->type_lengths[tmp - 1],
8271 101395038 field_charset);
8272 101479446 return val_ptr;
8273 }
8274
8275 59338 int Field_enum::cmp(const uchar *a_ptr, const uchar *b_ptr) const {
8276 const longlong a =
8277 59338 enum_val_int(a_ptr, packlength, table->s->db_low_byte_first);
8278 const longlong b =
8279 59338 enum_val_int(b_ptr, packlength, table->s->db_low_byte_first);
8280
4/4
✓ Branch 0 taken 59069 times.
✓ Branch 1 taken 269 times.
✓ Branch 2 taken 391 times.
✓ Branch 3 taken 58678 times.
59338 return (a < b) ? -1 : (a > b) ? 1 : 0;
8281 }
8282
8283 548 size_t Field_enum::make_sort_key(uchar *to, size_t length) const {
8284 #ifdef WORDS_BIGENDIAN
8285 if (!table->s->db_low_byte_first)
8286 copy_integer<true>(to, length, ptr, packlength, true);
8287 else
8288 #endif
8289 548 copy_integer<false>(to, length, ptr, packlength, true);
8290 548 return length;
8291 }
8292
8293 1297485 void Field_enum::sql_type(String &res) const {
8294 char buffer[255];
8295 1297485 String enum_item(buffer, sizeof(buffer), res.charset());
8296
8297 1297485 res.length(0);
8298
1/2
✓ Branch 0 taken 1297485 times.
✗ Branch 1 not taken.
1297485 res.append(STRING_WITH_LEN("enum("));
8299
8300 1297485 bool flag = false;
8301 1297485 uint *len = typelib->type_lengths;
8302
2/2
✓ Branch 0 taken 4251740 times.
✓ Branch 1 taken 1297485 times.
5549225 for (const char **pos = typelib->type_names; *pos; pos++, len++) {
8303 uint dummy_errors;
8304
3/4
✓ Branch 0 taken 2954255 times.
✓ Branch 1 taken 1297485 times.
✓ Branch 2 taken 2954255 times.
✗ Branch 3 not taken.
4251740 if (flag) res.append(',');
8305 /* convert to res.charset() == utf8, then quote */
8306
2/4
✓ Branch 0 taken 4251740 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4251740 times.
✗ Branch 3 not taken.
4251740 enum_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors);
8307
8308 4251740 const CHARSET_INFO *cs = res.charset();
8309 4251740 int well_formed_error = 42;
8310 #ifndef NDEBUG
8311 size_t wl =
8312 #endif
8313
1/2
✓ Branch 0 taken 4251740 times.
✗ Branch 1 not taken.
8503480 cs->cset->well_formed_len(cs, enum_item.ptr(),
8314 4251740 enum_item.ptr() + enum_item.length(),
8315 enum_item.length(), &well_formed_error);
8316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4251740 times.
4251740 assert(wl <= enum_item.length());
8317
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4251732 times.
4251740 if (well_formed_error) {
8318 // Append the hex literal instead
8319
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 res.append("x'");
8320 char b[6];
8321 8 const char *eip = enum_item.ptr();
8322
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 8 times.
30 for (size_t i = 0; i < enum_item.length(); ++i) {
8323 22 unsigned char v = static_cast<unsigned char>(eip[i]);
8324 22 snprintf(b, sizeof(b), "%x", v);
8325
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 res.append(b);
8326 }
8327
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 res.append("'");
8328 } else {
8329
1/2
✓ Branch 0 taken 4251732 times.
✗ Branch 1 not taken.
4251732 append_unescaped(&res, enum_item.ptr(), enum_item.length());
8330 }
8331 4251740 flag = true;
8332 }
8333
1/2
✓ Branch 0 taken 1297485 times.
✗ Branch 1 not taken.
1297485 res.append(')');
8334 1297485 }
8335
8336 368370 Field *Field_enum::new_field(MEM_ROOT *root, TABLE *new_table) const {
8337 368370 Field_enum *res = down_cast<Field_enum *>(Field::new_field(root, new_table));
8338
1/2
✓ Branch 0 taken 368370 times.
✗ Branch 1 not taken.
368370 if (res) res->typelib = copy_typelib(root, typelib);
8339 368370 return res;
8340 }
8341
8342 /*
8343 set type.
8344 This is a string which can have a collection of different values.
8345 Each string value is separated with a ','.
8346 For example "One,two,five"
8347 If one uses this string in a number context one gets the bits as a longlong
8348 number.
8349 */
8350
8351 329369 type_conversion_status Field_set::store(const char *from, size_t length,
8352 const CHARSET_INFO *cs) {
8353
4/6
✓ Branch 0 taken 329369 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 317094 times.
✓ Branch 3 taken 12275 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 317094 times.
329369 ASSERT_COLUMN_MARKED_FOR_WRITE;
8354 329369 bool got_warning = false;
8355 329369 int err = 0;
8356 329369 type_conversion_status ret = TYPE_OK;
8357 const char *not_used;
8358 uint not_used2;
8359 char buff[STRING_BUFFER_USUAL_SIZE];
8360 329369 String tmpstr(buff, sizeof(buff), &my_charset_bin);
8361
8362 /* Convert character set if necessary */
8363
3/4
✓ Branch 0 taken 329369 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19991 times.
✓ Branch 3 taken 309378 times.
329369 if (String::needs_conversion_on_storage(length, cs, field_charset)) {
8364 uint dummy_errors;
8365
1/2
✓ Branch 0 taken 19991 times.
✗ Branch 1 not taken.
19991 tmpstr.copy(from, length, cs, field_charset, &dummy_errors);
8366 19991 from = tmpstr.ptr();
8367 19991 length = tmpstr.length();
8368 }
8369
1/2
✓ Branch 0 taken 329369 times.
✗ Branch 1 not taken.
329369 ulonglong tmp = find_set(typelib, from, length, field_charset, &not_used,
8370 &not_used2, &got_warning);
8371
6/6
✓ Branch 0 taken 38311 times.
✓ Branch 1 taken 291058 times.
✓ Branch 2 taken 240 times.
✓ Branch 3 taken 38071 times.
✓ Branch 4 taken 218 times.
✓ Branch 5 taken 22 times.
329369 if (!tmp && length && length < 22) {
8372 /* This is for reading numbers with LOAD DATA INFILE */
8373 const char *end;
8374
1/2
✓ Branch 0 taken 218 times.
✗ Branch 1 not taken.
218 tmp = my_strntoull(cs, from, length, 10, &end, &err);
8375
4/4
✓ Branch 0 taken 170 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 163 times.
✓ Branch 3 taken 7 times.
218 if (err || end != from + length ||
8376
4/4
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 150 times.
163 (typelib->count < 64 && tmp >= (1ULL << typelib->count))) {
8377 67 tmp = 0;
8378
1/2
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
67 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
8379 67 ret = TYPE_WARN_TRUNCATED;
8380 }
8381
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 329124 times.
329369 } else if (got_warning)
8382
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
8383
1/2
✓ Branch 0 taken 329369 times.
✗ Branch 1 not taken.
329369 store_type(tmp);
8384 329369 return ret;
8385 329369 }
8386
8387 65145 type_conversion_status Field_set::store(longlong nr, bool) {
8388
4/6
✓ Branch 0 taken 65145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 65141 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 65141 times.
65145 ASSERT_COLUMN_MARKED_FOR_WRITE;
8389 65145 type_conversion_status error = TYPE_OK;
8390 ulonglong max_nr;
8391
8392
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 65143 times.
65145 if (sizeof(ulonglong) * 8 <= typelib->count)
8393 2 max_nr = ULLONG_MAX;
8394 else
8395 65143 max_nr = (1ULL << typelib->count) - 1;
8396
8397
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 65137 times.
65145 if ((ulonglong)nr > max_nr) {
8398 8 nr &= max_nr;
8399 8 set_warning(Sql_condition::SL_WARNING, WARN_DATA_TRUNCATED, 1);
8400 8 error = TYPE_WARN_TRUNCATED;
8401 }
8402 65145 store_type((ulonglong)nr);
8403 65145 return error;
8404 }
8405
8406 688444 String *Field_set::val_str(String *val_buffer, String *) const {
8407 688444 ulonglong tmp = (ulonglong)Field_enum::val_int();
8408 688444 uint bitnr = 0;
8409
8410 /*
8411 Some callers expect *val_buffer to contain the result,
8412 so we assign to it, rather than doing 'return &empty_set_string.
8413 */
8414 688444 *val_buffer = empty_set_string;
8415
2/2
✓ Branch 0 taken 110850 times.
✓ Branch 1 taken 577594 times.
688444 if (tmp == 0) {
8416 110850 return val_buffer;
8417 }
8418
8419 577594 val_buffer->set_charset(field_charset);
8420 577594 val_buffer->length(0);
8421
8422
4/4
✓ Branch 0 taken 17110885 times.
✓ Branch 1 taken 577590 times.
✓ Branch 2 taken 17110881 times.
✓ Branch 3 taken 4 times.
17688475 while (tmp && bitnr < typelib->count) {
8423
2/2
✓ Branch 0 taken 3329180 times.
✓ Branch 1 taken 13781701 times.
17110881 if (tmp & 1) {
8424
2/2
✓ Branch 0 taken 2751590 times.
✓ Branch 1 taken 577590 times.
3329180 if (val_buffer->length())
8425
1/2
✓ Branch 0 taken 2751590 times.
✗ Branch 1 not taken.
2751590 val_buffer->append(&field_separator, 1, &my_charset_latin1);
8426 3329180 String str(typelib->type_names[bitnr], typelib->type_lengths[bitnr],
8427 3329180 field_charset);
8428
1/2
✓ Branch 0 taken 3329180 times.
✗ Branch 1 not taken.
3329180 val_buffer->append(str);
8429 3329180 }
8430 17110881 tmp >>= 1;
8431 17110881 bitnr++;
8432 }
8433 577594 return val_buffer;
8434 }
8435
8436 96332 void Field_set::sql_type(String &res) const {
8437 char buffer[255];
8438 96332 String set_item(buffer, sizeof(buffer), res.charset());
8439
8440 96332 res.length(0);
8441
1/2
✓ Branch 0 taken 96332 times.
✗ Branch 1 not taken.
96332 res.append(STRING_WITH_LEN("set("));
8442
8443 96332 bool flag = false;
8444 96332 uint *len = typelib->type_lengths;
8445
2/2
✓ Branch 0 taken 1361165 times.
✓ Branch 1 taken 96332 times.
1457497 for (const char **pos = typelib->type_names; *pos; pos++, len++) {
8446 uint dummy_errors;
8447
3/4
✓ Branch 0 taken 1264833 times.
✓ Branch 1 taken 96332 times.
✓ Branch 2 taken 1264833 times.
✗ Branch 3 not taken.
1361165 if (flag) res.append(',');
8448 /* convert to res.charset() == utf8, then quote */
8449
1/2
✓ Branch 0 taken 1361165 times.
✗ Branch 1 not taken.
1361165 set_item.copy(*pos, *len, charset(), res.charset(), &dummy_errors);
8450
1/2
✓ Branch 0 taken 1361165 times.
✗ Branch 1 not taken.
1361165 append_unescaped(&res, set_item.ptr(), set_item.length());
8451 1361165 flag = true;
8452 }
8453
1/2
✓ Branch 0 taken 96332 times.
✗ Branch 1 not taken.
96332 res.append(')');
8454 96332 }
8455
8456 /**
8457 @retval
8458 true if the fields are equally defined
8459 @retval
8460 false if the fields are unequally defined
8461 */
8462
8463 7074006 bool Field::eq_def(const Field *field) const {
8464
6/6
✓ Branch 0 taken 7038568 times.
✓ Branch 1 taken 35533 times.
✓ Branch 2 taken 7017189 times.
✓ Branch 3 taken 21330 times.
✓ Branch 4 taken 57549 times.
✓ Branch 5 taken 7016507 times.
14091199 if (real_type() != field->real_type() || charset() != field->charset() ||
8465
2/2
✓ Branch 0 taken 686 times.
✓ Branch 1 taken 7016507 times.
7017189 pack_length() != field->pack_length())
8466 57549 return false;
8467 7016507 return true;
8468 }
8469
8470 /**
8471 Compare the first t1::count type names.
8472
8473 @return true if the type names of t1 match those of t2. false otherwise.
8474 */
8475
8476 609089 static bool compare_type_names(const CHARSET_INFO *charset, TYPELIB *t1,
8477 TYPELIB *t2) {
8478
2/2
✓ Branch 0 taken 3302594 times.
✓ Branch 1 taken 609062 times.
3911656 for (uint i = 0; i < t1->count; i++)
8479
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3302567 times.
3302594 if (my_strnncoll(charset, (const uchar *)t1->type_names[i],
8480 t1->type_lengths[i], (const uchar *)t2->type_names[i],
8481 t2->type_lengths[i]))
8482 27 return false;
8483 609062 return true;
8484 }
8485
8486 /**
8487 @return
8488 returns 1 if the fields are equally defined
8489 */
8490
8491 368165 bool Field_enum::eq_def(const Field *field) const {
8492 TYPELIB *values;
8493
8494
2/2
✓ Branch 0 taken 8467 times.
✓ Branch 1 taken 359698 times.
368165 if (!Field::eq_def(field)) return false;
8495
8496 359698 values = down_cast<const Field_enum *>(field)->typelib;
8497
8498 /* Definition must be strictly equal. */
8499
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 359675 times.
359698 if (typelib->count != values->count) return false;
8500
8501 359675 return compare_type_names(field_charset, typelib, values);
8502 }
8503
8504 /**
8505 Check whether two fields can be considered 'equal' for table
8506 alteration purposes. Fields are equal if they retain the same
8507 pack length and if new members are added to the end of the list.
8508
8509 @return IS_EQUAL_YES if fields are compatible.
8510 IS_EQUAL_NO otherwise.
8511 */
8512
8513 249451 uint Field_enum::is_equal(const Create_field *new_field) const {
8514
1/2
✓ Branch 0 taken 249451 times.
✗ Branch 1 not taken.
249451 DBUG_TRACE;
8515 /*
8516 The fields are compatible if they have the same flags,
8517 type, charset and have the same underlying length.
8518 */
8519
3/4
✓ Branch 0 taken 249451 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 249432 times.
249451 if (sql_type_prevents_inplace(*this, *new_field)) {
8520
3/8
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 19 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
19 DBUG_PRINT("inplace", ("-> IS_EQUAL_NO"));
8521 19 return IS_EQUAL_NO;
8522 }
8523 249432 TYPELIB *new_typelib = new_field->interval;
8524
8525 /*
8526 Changing the definition of an ENUM or SET column by adding a new
8527 enumeration or set members to the end of the list of valid member
8528 values only alters table metadata and not table data.
8529 */
8530
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 249414 times.
249432 if (typelib->count > new_typelib->count) {
8531
3/8
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18 DBUG_PRINT("inplace", ("(typelib->count > new_typelib->count) -> "
8532 "IS_EQUAL_NO"));
8533 18 return IS_EQUAL_NO;
8534 }
8535
8536 /* Check whether there are modification before the end. Since we
8537 know that the charset change (if there is one) is
8538 inplace-compatible, it is safe to perform the comparison using the
8539 new charset.
8540 */
8541
3/4
✓ Branch 0 taken 249414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✓ Branch 3 taken 249387 times.
249414 if (!compare_type_names(new_field->charset, typelib, new_typelib)) {
8542
3/8
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 27 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
27 DBUG_PRINT("inplace", ("!compare_type_names() -> IS_EQUAL_NO"));
8543 27 return IS_EQUAL_NO;
8544 }
8545
8546
3/12
✓ Branch 0 taken 249387 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 249387 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 249387 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
249387 DBUG_PRINT("inplace",
8547 ("Field_enum::is_equal() -> %s",
8548 (new_field->pack_length() == pack_length() ? "IS_EQUAL_YES"
8549 : "IS_EQUAL_NO")));
8550
8551 // Can't return IS_EQUAL_PACK_LENGTH here as using inplace leads to
8552 // assert when trying to insert set elements that use bits outside
8553 // the original length:
8554 // Assertion failure: rem0rec.cc:408:len <= fixed_len thread 140301224261376
8555
3/4
✓ Branch 0 taken 249387 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 249371 times.
✓ Branch 3 taken 16 times.
249387 return (new_field->pack_length() == pack_length() ? IS_EQUAL_YES
8556 249387 : IS_EQUAL_NO);
8557 249451 }
8558
8559 2359345 uchar *Field_enum::pack(uchar *to, const uchar *from, size_t max_length) const {
8560
1/2
✓ Branch 0 taken 2359345 times.
✗ Branch 1 not taken.
2359345 DBUG_TRACE;
8561
5/8
✓ Branch 0 taken 2359345 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2359345 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 633 times.
✓ Branch 5 taken 2358712 times.
✓ Branch 6 taken 633 times.
✗ Branch 7 not taken.
2359345 DBUG_PRINT("debug", ("packlength: %d", packlength));
8562
1/2
✓ Branch 0 taken 2359345 times.
✗ Branch 1 not taken.
2359345 DBUG_DUMP("from", from, packlength);
8563
8564
4/6
✓ Branch 0 taken 2351336 times.
✓ Branch 1 taken 7658 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✓ Branch 4 taken 289 times.
✗ Branch 5 not taken.
2359345 switch (packlength) {
8565 2351336 case 1:
8566
1/2
✓ Branch 0 taken 2351336 times.
✗ Branch 1 not taken.
2351336 if (max_length > 0) *to = *from;
8567 2351336 return to + 1;
8568 7658 case 2:
8569
1/2
✓ Branch 0 taken 7658 times.
✗ Branch 1 not taken.
7658 return pack_int16(to, from, max_length);
8570 case 3:
8571 return pack_int24(to, from, max_length);
8572 62 case 4:
8573
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 return pack_int32(to, from, max_length);
8574 289 case 8:
8575
1/2
✓ Branch 0 taken 289 times.
✗ Branch 1 not taken.
289 return pack_int64(to, from, max_length);
8576 default:
8577 assert(0);
8578 }
8579 MY_ASSERT_UNREACHABLE();
8580 return nullptr;
8581 2359345 }
8582
8583 2314855 const uchar *Field_enum::unpack(uchar *to, const uchar *from, uint) {
8584
1/2
✓ Branch 0 taken 2314855 times.
✗ Branch 1 not taken.
2314855 DBUG_TRACE;
8585
3/8
✓ Branch 0 taken 2314855 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2314855 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2314855 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2314855 DBUG_PRINT("debug", ("packlength: %d", packlength));
8586
1/2
✓ Branch 0 taken 2314855 times.
✗ Branch 1 not taken.
2314855 DBUG_DUMP("from", from, packlength);
8587
8588
3/6
✓ Branch 0 taken 2311317 times.
✓ Branch 1 taken 3357 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 181 times.
✗ Branch 5 not taken.
2314855 switch (packlength) {
8589 2311317 case 1:
8590 2311317 *to = *from;
8591 2311317 return from + 1;
8592
8593 3357 case 2:
8594
1/2
✓ Branch 0 taken 3357 times.
✗ Branch 1 not taken.
3357 return unpack_int16(to, from);
8595 case 3:
8596 return unpack_int24(to, from);
8597 case 4:
8598 return unpack_int32(to, from);
8599 181 case 8:
8600
1/2
✓ Branch 0 taken 181 times.
✗ Branch 1 not taken.
181 return unpack_int64(to, from);
8601 default:
8602 assert(0);
8603 }
8604 MY_ASSERT_UNREACHABLE();
8605 return nullptr;
8606 2314855 }
8607
8608 /**
8609 @return
8610 returns true if the fields are equally defined
8611 */
8612 4370704 bool Field_num::eq_def(const Field *field) const {
8613
2/2
✓ Branch 0 taken 7581 times.
✓ Branch 1 taken 4363210 times.
4370704 if (!Field::eq_def(field)) return false;
8614 4363210 const Field_num *from_num = down_cast<const Field_num *>(field);
8615
8616 4363205 if (is_unsigned() != from_num->is_unsigned() ||
8617
8/12
✓ Branch 0 taken 4362129 times.
✓ Branch 1 taken 1151 times.
✓ Branch 2 taken 4619 times.
✓ Branch 3 taken 4357510 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4619 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4362154 times.
✓ Branch 10 taken 1126 times.
✓ Branch 11 taken 4362154 times.
4363280 (zerofill && !from_num->zerofill && !zero_pack()) || dec != from_num->dec)
8618 1126 return false;
8619 4362154 return true;
8620 }
8621
8622 /**
8623 Check whether two numeric fields can be considered 'equal' for table
8624 alteration purposes. Fields are equal if they are of the same type
8625 and retain the same pack length.
8626 */
8627
8628 226464 uint Field_num::is_equal(const Create_field *new_field) const {
8629
2/2
✓ Branch 0 taken 225145 times.
✓ Branch 1 taken 166 times.
451775 return (new_field->sql_type == real_type()) &&
8630 225311 (Overlaps(new_field->flags, UNSIGNED_FLAG) ==
8631
2/2
✓ Branch 0 taken 225106 times.
✓ Branch 1 taken 39 times.
450456 is_flag_set(UNSIGNED_FLAG)) &&
8632 225145 (Overlaps(new_field->flags, AUTO_INCREMENT_FLAG) ==
8633
2/2
✓ Branch 0 taken 225311 times.
✓ Branch 1 taken 1153 times.
676920 is_flag_set(AUTO_INCREMENT_FLAG)) &&
8634
1/2
✓ Branch 0 taken 225106 times.
✗ Branch 1 not taken.
451570 (new_field->pack_length() == pack_length());
8635 }
8636
8637 /*
8638 Bit field.
8639
8640 We store the first 0 - 6 uneven bits among the null bits
8641 at the start of the record. The rest bytes are stored in
8642 the record itself.
8643
8644 For example:
8645
8646 CREATE TABLE t1 (a int, b bit(17), c bit(21) not null, d bit(8));
8647 We would store data as follows in the record:
8648
8649 Byte Bit
8650 1 7 - reserve for delete
8651 6 - null bit for 'a'
8652 5 - null bit for 'b'
8653 4 - first (high) bit of 'b'
8654 3 - first (high) bit of 'c'
8655 2 - second bit of 'c'
8656 1 - third bit of 'c'
8657 0 - forth bit of 'c'
8658 2 7 - firth bit of 'c'
8659 6 - null bit for 'd'
8660 3 - 6 four bytes for 'a'
8661 7 - 8 two bytes for 'b'
8662 9 - 10 two bytes for 'c'
8663 11 one byte for 'd'
8664 */
8665
8666 14273 Field_bit::Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
8667 uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
8668 14273 uchar auto_flags_arg, const char *field_name_arg)
8669 : Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
8670 field_name_arg),
8671 14273 bit_ptr(bit_ptr_arg),
8672 14273 bit_ofs(bit_ofs_arg),
8673 14273 bit_len(len_arg & 7),
8674 14273 bytes_in_rec(len_arg / 8) {
8675
1/2
✓ Branch 0 taken 14273 times.
✗ Branch 1 not taken.
14273 DBUG_TRACE;
8676
3/8
✓ Branch 0 taken 14273 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14273 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14273 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
14273 DBUG_PRINT("enter", ("ptr_arg: %p, null_ptr_arg: %p, len_arg: %u, bit_len: "
8677 "%u, bytes_in_rec: %u",
8678 ptr_arg, null_ptr_arg, len_arg, bit_len, bytes_in_rec));
8679 14273 set_flag(UNSIGNED_FLAG);
8680 /*
8681 Ensure that Field::eq() can distinguish between two different bit fields.
8682 (two bit fields that are not null, may have same ptr and m_null_ptr)
8683 */
8684
2/2
✓ Branch 0 taken 6503 times.
✓ Branch 1 taken 7770 times.
14273 if (!null_ptr_arg) null_bit = bit_ofs_arg;
8685 14273 }
8686
8687 1229 void Field_bit::hash(ulong *nr, ulong *nr2) const {
8688
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1224 times.
1229 if (is_null()) {
8689 5 *nr ^= (*nr << 1) | 1;
8690 } else {
8691 1224 const CHARSET_INFO *cs = &my_charset_bin;
8692
1/2
✓ Branch 0 taken 1224 times.
✗ Branch 1 not taken.
1224 longlong value = Field_bit::val_int();
8693 uchar tmp[8];
8694 1224 mi_int8store(tmp, value);
8695
8696 1224 uint64 tmp1 = *nr;
8697 1224 uint64 tmp2 = *nr2;
8698
1/2
✓ Branch 0 taken 1224 times.
✗ Branch 1 not taken.
1224 cs->coll->hash_sort(cs, tmp, 8, &tmp1, &tmp2);
8699
8700 // NOTE: This truncates to 32-bit on Windows, to keep on-disk stability.
8701 1224 *nr = static_cast<ulong>(tmp1);
8702 1224 *nr2 = static_cast<ulong>(tmp2);
8703 }
8704 1229 }
8705
8706 574 Field *Field_bit::new_key_field(MEM_ROOT *root, TABLE *new_table,
8707 uchar *new_ptr, uchar *new_null_ptr,
8708 uint new_null_bit) const {
8709 Field_bit *res;
8710
1/2
✓ Branch 0 taken 574 times.
✗ Branch 1 not taken.
574 if ((res = (Field_bit *)Field::new_key_field(root, new_table, new_ptr,
8711 new_null_ptr, new_null_bit))) {
8712 /* Move bits normally stored in null_pointer to new_ptr */
8713 574 res->bit_ptr = new_ptr;
8714 574 res->bit_ofs = 0;
8715
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 570 times.
574 if (bit_len) res->ptr++; // Store rest of data here
8716 }
8717 574 return res;
8718 }
8719
8720 522 uint Field_bit::is_equal(const Create_field *new_field) const {
8721
1/2
✓ Branch 0 taken 522 times.
✗ Branch 1 not taken.
1044 return (new_field->sql_type == real_type() &&
8722
2/2
✓ Branch 0 taken 505 times.
✓ Branch 1 taken 17 times.
1044 new_field->max_display_width_in_bytes() == max_display_length());
8723 }
8724
8725 17001 type_conversion_status Field_bit::reset() {
8726 17001 memset(ptr, 0, bytes_in_rec);
8727
4/4
✓ Branch 0 taken 3685 times.
✓ Branch 1 taken 13316 times.
✓ Branch 2 taken 1079 times.
✓ Branch 3 taken 2606 times.
17001 if (bit_ptr && (bit_len > 0)) // reset odd bits among null bits
8728
2/2
✓ Branch 0 taken 154 times.
✓ Branch 1 taken 925 times.
1079 clr_rec_bits(bit_ptr, bit_ofs, bit_len);
8729 17001 return TYPE_OK;
8730 }
8731
8732 730 type_conversion_status Field_bit::store(const char *from, size_t length,
8733 const CHARSET_INFO *) {
8734
4/6
✓ Branch 0 taken 730 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 720 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 720 times.
730 ASSERT_COLUMN_MARKED_FOR_WRITE;
8735 int delta;
8736
8737
4/4
✓ Branch 0 taken 5373 times.
✓ Branch 1 taken 155 times.
✓ Branch 2 taken 4798 times.
✓ Branch 3 taken 575 times.
5528 for (; length && !*from; from++, length--)
8738 ; // skip left 0's
8739 730 delta = bytes_in_rec - static_cast<int>(length);
8740
8741 /*
8742 *from should probably be treated like uint here see BUG#13727586
8743 */
8744
5/6
✓ Branch 0 taken 730 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 375 times.
✓ Branch 3 taken 355 times.
✓ Branch 4 taken 324 times.
✓ Branch 5 taken 51 times.
730 if (delta < -1 || (delta == -1 && (uchar)*from > ((1 << bit_len) - 1)) ||
8745
3/4
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 587 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 92 times.
679 (!bit_len && delta < 0)) {
8746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 set_rec_bits((1 << bit_len) - 1, bit_ptr, bit_ofs, bit_len);
8747 51 memset(ptr, 0xff, bytes_in_rec);
8748
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if (current_thd->is_strict_mode())
8749 51 set_warning(Sql_condition::SL_WARNING, ER_DATA_TOO_LONG, 1);
8750 else
8751 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
8752 51 return TYPE_WARN_OUT_OF_RANGE;
8753 }
8754 /* delta is >= -1 here */
8755
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 571 times.
679 if (delta > 0) {
8756
3/4
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 72 times.
108 if (bit_len) clr_rec_bits(bit_ptr, bit_ofs, bit_len);
8757 108 memset(ptr, 0, delta);
8758 108 memcpy(ptr + delta, from, length);
8759
2/2
✓ Branch 0 taken 247 times.
✓ Branch 1 taken 324 times.
571 } else if (delta == 0) {
8760
4/4
✓ Branch 0 taken 191 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 169 times.
247 if (bit_len) clr_rec_bits(bit_ptr, bit_ofs, bit_len);
8761 247 memcpy(ptr, from, length);
8762 } else {
8763
1/2
✓ Branch 0 taken 324 times.
✗ Branch 1 not taken.
324 if (bit_len) {
8764
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 187 times.
324 set_rec_bits((uchar)*from, bit_ptr, bit_ofs, bit_len);
8765 324 from++;
8766 }
8767 324 memcpy(ptr, from, bytes_in_rec);
8768 }
8769 679 return TYPE_OK;
8770 }
8771
8772 258 type_conversion_status Field_bit::store(double nr) {
8773
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 257 times.
258 if (nr < LLONG_MIN)
8774 1 return Field_bit::store(static_cast<longlong>(LLONG_MIN), false);
8775
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 256 times.
257 if (nr > LLONG_MAX_DOUBLE)
8776 1 return Field_bit::store(static_cast<longlong>(LLONG_MAX), false);
8777 256 return Field_bit::store(static_cast<longlong>(nr), false);
8778 }
8779
8780 92801 type_conversion_status Field_bit::store(longlong nr, bool) {
8781 char buf[8];
8782
8783 92801 mi_int8store(buf, nr);
8784
1/2
✓ Branch 0 taken 92801 times.
✗ Branch 1 not taken.
185602 return store(buf, 8, nullptr);
8785 }
8786
8787 type_conversion_status Field_bit::store_decimal(const my_decimal *val) {
8788 bool has_overflow = false;
8789 longlong i = convert_decimal2longlong(val, true, &has_overflow);
8790 type_conversion_status res = store(i, true);
8791 return has_overflow ? TYPE_WARN_OUT_OF_RANGE : res;
8792 }
8793
8794 28012 double Field_bit::val_real() const {
8795 28012 return static_cast<double>(static_cast<ulonglong>(Field_bit::val_int()));
8796 }
8797
8798 450834 longlong Field_bit::val_int() const {
8799
4/6
✓ Branch 0 taken 450834 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 450764 times.
✓ Branch 3 taken 70 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 450764 times.
450834 ASSERT_COLUMN_MARKED_FOR_READ;
8800 450834 ulonglong bits = 0;
8801
2/2
✓ Branch 0 taken 1555 times.
✓ Branch 1 taken 449279 times.
450834 if (bit_len) {
8802 1555 bits = get_rec_bits(bit_ptr, bit_ofs, bit_len);
8803 1555 bits <<= (bytes_in_rec * 8);
8804 }
8805
8806
7/9
✓ Branch 0 taken 1090 times.
✓ Branch 1 taken 144069 times.
✓ Branch 2 taken 91024 times.
✓ Branch 3 taken 52 times.
✓ Branch 4 taken 99221 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3335 times.
✓ Branch 8 taken 112043 times.
450834 switch (bytes_in_rec) {
8807 1090 case 0:
8808 1090 return bits;
8809 144069 case 1:
8810 144069 return bits | (ulonglong)ptr[0];
8811 91024 case 2:
8812 91024 return bits | mi_uint2korr(ptr);
8813 52 case 3:
8814 52 return bits | mi_uint3korr(ptr);
8815 99221 case 4:
8816 99221 return bits | mi_uint4korr(ptr);
8817 case 5:
8818 return bits | mi_uint5korr(ptr);
8819 case 6:
8820 return bits | mi_uint6korr(ptr);
8821 3335 case 7:
8822 3335 return bits | mi_uint7korr(ptr);
8823 112043 default:
8824 112043 return mi_uint8korr(ptr + bytes_in_rec - sizeof(longlong));
8825 }
8826 }
8827
8828 36553 String *Field_bit::val_str(String *val_buffer, String *) const {
8829
4/6
✓ Branch 0 taken 36553 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36552 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 36552 times.
36553 ASSERT_COLUMN_MARKED_FOR_READ;
8830 char buff[sizeof(longlong)];
8831 36553 uint length = min<uint>(pack_length(), sizeof(longlong));
8832
1/2
✓ Branch 0 taken 36553 times.
✗ Branch 1 not taken.
36553 ulonglong bits = val_int();
8833 36553 mi_int8store(buff, bits);
8834
8835
1/2
✓ Branch 0 taken 36553 times.
✗ Branch 1 not taken.
36553 val_buffer->alloc(length);
8836 36553 memcpy(val_buffer->ptr(), buff + 8 - length, length);
8837 36553 val_buffer->length(length);
8838 36553 val_buffer->set_charset(&my_charset_bin);
8839 36553 return val_buffer;
8840 }
8841
8842 16 my_decimal *Field_bit::val_decimal(my_decimal *deciaml_value) const {
8843
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 16 times.
16 ASSERT_COLUMN_MARKED_FOR_READ;
8844 16 int2my_decimal(E_DEC_FATAL_ERROR, val_int(), true, deciaml_value);
8845 16 return deciaml_value;
8846 }
8847
8848 /*
8849 Compare two bit fields using pointers within the record.
8850 SYNOPSIS
8851 cmp_max()
8852 a Pointer to field->ptr in first record
8853 b Pointer to field->ptr in second record
8854 DESCRIPTION
8855 This method is used from key_rec_cmp used by merge sorts used
8856 by partitioned index read and later other similar places.
8857 The a and b pointer must be pointers to the field in a record
8858 (not the table->record[0] necessarily)
8859 */
8860 6 int Field_bit::cmp_max(const uchar *a, const uchar *b, uint) const {
8861 6 ptrdiff_t a_diff = a - ptr;
8862 6 ptrdiff_t b_diff = b - ptr;
8863
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (bit_len) {
8864 int flag;
8865 uchar bits_a = get_rec_bits(bit_ptr + a_diff, bit_ofs, bit_len);
8866 uchar bits_b = get_rec_bits(bit_ptr + b_diff, bit_ofs, bit_len);
8867 if ((flag = (int)(bits_a - bits_b))) return flag;
8868 }
8869 6 return memcmp(a, b, pack_length());
8870 }
8871
8872 4541 int Field_bit::key_cmp(const uchar *str, uint length) const {
8873
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4528 times.
4541 if (bit_len) {
8874 int flag;
8875 13 uchar bits = get_rec_bits(bit_ptr, bit_ofs, bit_len);
8876
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 3 times.
13 if ((flag = (int)(bits - *str))) return flag;
8877 3 str++;
8878 3 length--;
8879 }
8880 4531 return memcmp(ptr, str, length);
8881 }
8882
8883 11036 int Field_bit::cmp_offset(ptrdiff_t row_offset) const {
8884
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 10995 times.
11036 if (bit_len) {
8885 int flag;
8886 41 uchar bits_a = get_rec_bits(bit_ptr, bit_ofs, bit_len);
8887 41 uchar bits_b = get_rec_bits(bit_ptr + row_offset, bit_ofs, bit_len);
8888
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if ((flag = (int)(bits_a - bits_b))) return flag;
8889 }
8890 11036 return memcmp(ptr, ptr + row_offset, bytes_in_rec);
8891 }
8892
8893 51595 size_t Field_bit::get_key_image(uchar *buff, size_t length, imagetype) const {
8894
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 51565 times.
51595 if (bit_len) {
8895 30 uchar bits = get_rec_bits(bit_ptr, bit_ofs, bit_len);
8896 30 *buff++ = bits;
8897 30 length--;
8898 }
8899 51595 size_t data_length = min(length, static_cast<size_t>(bytes_in_rec));
8900 51595 memcpy(buff, ptr, data_length);
8901 51595 return data_length + 1;
8902 }
8903
8904 /**
8905 Save the field metadata for bit fields.
8906
8907 Saves the bit length in the first byte and bytes in record in the
8908 second byte of the field metadata array at index of *metadata_ptr and
8909 *(metadata_ptr + 1).
8910
8911 @param metadata_ptr First byte of field metadata
8912
8913 @returns number of bytes written to metadata_ptr
8914 */
8915 26261 int Field_bit::do_save_field_metadata(uchar *metadata_ptr) const {
8916
1/2
✓ Branch 0 taken 26261 times.
✗ Branch 1 not taken.
26261 DBUG_TRACE;
8917
3/8
✓ Branch 0 taken 26261 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26261 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 26261 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
26261 DBUG_PRINT("debug", ("bit_len: %d, bytes_in_rec: %d", bit_len, bytes_in_rec));
8918 /*
8919 Since this class and Field_bit_as_char have different ideas of
8920 what should be stored here, we compute the values of the metadata
8921 explicitly using the field_length.
8922 */
8923 26261 metadata_ptr[0] = field_length % 8;
8924 26261 metadata_ptr[1] = field_length / 8;
8925 26261 return 2;
8926 26261 }
8927
8928 /**
8929 Returns the number of bytes field uses in row-based replication
8930 row packed size.
8931
8932 This method is used in row-based replication to determine the number
8933 of bytes that the field consumes in the row record format. This is
8934 used to skip fields in the master that do not exist on the slave.
8935
8936 @param field_metadata Encoded size in field metadata
8937
8938 @returns The size of the field based on the field metadata.
8939 */
8940 uint Field_bit::pack_length_from_metadata(uint field_metadata) const {
8941 uint const from_len = (field_metadata >> 8U) & 0x00ff;
8942 uint const from_bit_len = field_metadata & 0x00ff;
8943 uint const source_size = from_len + ((from_bit_len > 0) ? 1 : 0);
8944 return (source_size);
8945 }
8946
8947 /**
8948 Check to see if field size is compatible with destination.
8949
8950 This method is used in row-based replication to verify that the slave's
8951 field size is less than or equal to the master's field size. The
8952 encoded field metadata (from the master or source) is decoded and compared
8953 to the size of this field (the slave or destination).
8954
8955 @param field_metadata Encoded size in field metadata
8956 @param mflags Flags from the table map event for the table.
8957 @param order_var Pointer to variable where the order
8958 between the source field and this field
8959 will be returned.
8960
8961 @return @c true
8962 */
8963 1165 bool Field_bit::compatible_field_size(uint field_metadata, Relay_log_info *,
8964 uint16 mflags, int *order_var) const {
8965
1/2
✓ Branch 0 taken 1165 times.
✗ Branch 1 not taken.
1165 DBUG_TRACE;
8966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1165 times.
1165 assert((field_metadata >> 16) == 0);
8967 1165 uint from_bit_len = 8 * (field_metadata >> 8) + (field_metadata & 0xff);
8968 1165 uint to_bit_len = max_display_length();
8969
3/8
✓ Branch 0 taken 1165 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1165 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1165 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1165 DBUG_PRINT("debug",
8970 ("from_bit_len: %u, to_bit_len: %u", from_bit_len, to_bit_len));
8971 /*
8972 If the bit length exact flag is clear, we are dealing with an old
8973 master, so we allow some less strict behaviour if replicating by
8974 moving both bit lengths to an even multiple of 8.
8975
8976 We do this by computing the number of bytes to store the field
8977 instead, and then compare the result.
8978 */
8979
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1165 times.
1165 if (!(mflags & Table_map_log_event::TM_BIT_LEN_EXACT_F)) {
8980 from_bit_len = (from_bit_len + 7) / 8;
8981 to_bit_len = (to_bit_len + 7) / 8;
8982 }
8983
8984 1165 *order_var = compare(from_bit_len, to_bit_len);
8985 1165 return true;
8986 1165 }
8987
8988 409 void Field_bit::sql_type(String &res) const {
8989 409 const CHARSET_INFO *cs = res.charset();
8990 409 size_t length = cs->cset->snprintf(cs, res.ptr(), res.alloced_length(),
8991 409 "bit(%d)", (int)field_length);
8992 409 res.length(length);
8993 409 }
8994
8995 64276 uchar *Field_bit::pack(uchar *to, const uchar *from, size_t max_length) const {
8996
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64276 times.
64276 if (max_length == 0) {
8997 return to + 1;
8998 }
8999 size_t length;
9000
2/2
✓ Branch 0 taken 1180 times.
✓ Branch 1 taken 63096 times.
64276 if (bit_len > 0) {
9001 /*
9002 We have the following:
9003
9004 ptr Points into a field in record R1
9005 from Points to a field in a record R2
9006 bit_ptr Points to the byte (in the null bytes) that holds the
9007 odd bits of R1
9008 from_bitp Points to the byte that holds the odd bits of R2
9009
9010 We have the following:
9011
9012 ptr - bit_ptr = from - from_bitp
9013
9014 We want to isolate 'from_bitp', so this gives:
9015
9016 ptr - bit_ptr - from = - from_bitp
9017 - ptr + bit_ptr + from = from_bitp
9018 bit_ptr + from - ptr = from_bitp
9019 */
9020 1180 uchar bits = get_rec_bits(bit_ptr + (from - ptr), bit_ofs, bit_len);
9021 1180 *to++ = bits;
9022 }
9023 64276 length = min<size_t>(bytes_in_rec, max_length - (bit_len > 0));
9024 64276 memcpy(to, from, length);
9025 64276 return to + length;
9026 }
9027
9028 /**
9029 Unpack a bit field from row data.
9030
9031 This method is used to unpack a bit field from a master whose size
9032 of the field is less than that of the slave.
9033
9034 @param to Destination of the data
9035 @param from Source of the data
9036 @param param_data Bit length (upper) and length (lower) values
9037
9038 @return New pointer into memory based on from + length of the data
9039 */
9040 3715 const uchar *Field_bit::unpack(uchar *to, const uchar *from, uint param_data) {
9041
1/2
✓ Branch 0 taken 3715 times.
✗ Branch 1 not taken.
3715 DBUG_TRACE;
9042
3/8
✓ Branch 0 taken 3715 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3715 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3715 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3715 DBUG_PRINT("enter",
9043 ("to: %p, from: %p, param_data: 0x%x", to, from, param_data));
9044
3/8
✓ Branch 0 taken 3715 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3715 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3715 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3715 DBUG_PRINT("debug", ("bit_ptr: %p, bit_len: %u, bit_ofs: %u", bit_ptr,
9045 bit_len, bit_ofs));
9046 3715 uint const from_len = (param_data >> 8U) & 0x00ff;
9047 3715 uint const from_bit_len = param_data & 0x00ff;
9048
3/8
✓ Branch 0 taken 3715 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3715 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3715 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3715 DBUG_PRINT("debug",
9049 ("from_len: %u, from_bit_len: %u", from_len, from_bit_len));
9050 /*
9051 If the parameter data is zero (i.e., undefined), or if the master
9052 and slave have the same sizes, then use the old unpack() method.
9053 */
9054
2/2
✓ Branch 0 taken 2638 times.
✓ Branch 1 taken 1077 times.
3715 if (param_data == 0 ||
9055
3/4
✓ Branch 0 taken 362 times.
✓ Branch 1 taken 2276 times.
✓ Branch 2 taken 362 times.
✗ Branch 3 not taken.
2638 ((from_bit_len == bit_len) && (from_len == bytes_in_rec))) {
9056
2/2
✓ Branch 0 taken 657 times.
✓ Branch 1 taken 782 times.
1439 if (bit_len > 0) {
9057 /*
9058 set_rec_bits is a macro, don't put the post-increment in the
9059 argument since that might cause strange side-effects.
9060
9061 For the choice of the second argument, see the explanation for
9062 Field_bit::pack().
9063 */
9064
2/2
✓ Branch 0 taken 195 times.
✓ Branch 1 taken 462 times.
657 set_rec_bits(*from, bit_ptr + (to - ptr), bit_ofs, bit_len);
9065 657 from++;
9066 }
9067 1439 memcpy(to, from, bytes_in_rec);
9068 1439 return from + bytes_in_rec;
9069 }
9070
9071 /*
9072 We are converting a smaller bit field to a larger one here.
9073 To do that, we first need to construct a raw value for the original
9074 bit value stored in the from buffer. Then that needs to be converted
9075 to the larger field then sent to store() for writing to the field.
9076 Lastly the odd bits need to be masked out if the bytes_in_rec > 0.
9077 Otherwise stray bits can cause spurious values.
9078 */
9079 2276 uint new_len = (field_length + 7) / 8;
9080 2276 char *value = (char *)my_alloca(new_len);
9081 2276 memset(value, 0, new_len);
9082
1/2
✓ Branch 0 taken 2276 times.
✗ Branch 1 not taken.
2276 uint len = from_len + ((from_bit_len > 0) ? 1 : 0);
9083 2276 memcpy(value + (new_len - len), from, len);
9084 /*
9085 Mask out the unused bits in the partial byte.
9086 TODO: Add code to the master to always mask these bits and remove
9087 the following.
9088 */
9089
3/4
✓ Branch 0 taken 2276 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1005 times.
✓ Branch 3 taken 1271 times.
2276 if ((from_bit_len > 0) && (from_len > 0))
9090 1005 value[new_len - len] = value[new_len - len] & ((1U << from_bit_len) - 1);
9091 2276 bitmap_set_bit(table->write_set, field_index());
9092
1/2
✓ Branch 0 taken 2276 times.
✗ Branch 1 not taken.
2276 store(value, new_len, system_charset_info);
9093 2276 return from + len;
9094 3715 }
9095
9096 540 void Field_bit::set_default() {
9097
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 539 times.
540 if (bit_len > 0) {
9098 1 ptrdiff_t offset = table->default_values_offset();
9099 1 uchar bits = get_rec_bits(bit_ptr + offset, bit_ofs, bit_len);
9100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 set_rec_bits(bits, bit_ptr, bit_ofs, bit_len);
9101 }
9102 540 Field::set_default();
9103 540 }
9104
9105 /*
9106 Bit field support for non-MyISAM tables.
9107 */
9108
9109 12971 Field_bit_as_char::Field_bit_as_char(uchar *ptr_arg, uint32 len_arg,
9110 uchar *null_ptr_arg, uchar null_bit_arg,
9111 uchar auto_flags_arg,
9112 12971 const char *field_name_arg)
9113 : Field_bit(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, nullptr, 0,
9114 12971 auto_flags_arg, field_name_arg) {
9115 12971 set_flag(UNSIGNED_FLAG);
9116 12971 bit_len = 0;
9117 12971 bytes_in_rec = (len_arg + 7) / 8;
9118 12971 }
9119
9120 101729 type_conversion_status Field_bit_as_char::store(const char *from, size_t length,
9121 const CHARSET_INFO *) {
9122
4/6
✓ Branch 0 taken 101729 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 101669 times.
✓ Branch 3 taken 60 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 101669 times.
101729 ASSERT_COLUMN_MARKED_FOR_WRITE;
9123 int delta;
9124 101729 uchar bits = (uchar)(field_length & 7);
9125
9126
4/4
✓ Branch 0 taken 728186 times.
✓ Branch 1 taken 2118 times.
✓ Branch 2 taken 628575 times.
✓ Branch 3 taken 99611 times.
730304 for (; length && !*from; from++, length--)
9127 ; // skip left 0's
9128 101729 delta = bytes_in_rec - static_cast<int>(length);
9129
9130
4/4
✓ Branch 0 taken 94481 times.
✓ Branch 1 taken 7248 times.
✓ Branch 2 taken 30529 times.
✓ Branch 3 taken 63952 times.
101729 if (delta < 0 ||
9131
4/4
✓ Branch 0 taken 12426 times.
✓ Branch 1 taken 18103 times.
✓ Branch 2 taken 8779 times.
✓ Branch 3 taken 3647 times.
30529 (delta == 0 && bits && (uint)(uchar)*from >= (uint)(1 << bits))) {
9132 16027 memset(ptr, 0xff, bytes_in_rec);
9133
2/2
✓ Branch 0 taken 11893 times.
✓ Branch 1 taken 4134 times.
16027 if (bits) *ptr &= ((1 << bits) - 1); /* set first uchar */
9134
2/2
✓ Branch 0 taken 95 times.
✓ Branch 1 taken 15932 times.
16027 if (current_thd->is_strict_mode())
9135 95 set_warning(Sql_condition::SL_WARNING, ER_DATA_TOO_LONG, 1);
9136 else
9137 15932 set_warning(Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE, 1);
9138 16027 return TYPE_WARN_OUT_OF_RANGE;
9139 }
9140 85702 memset(ptr, 0, delta);
9141 85702 memcpy(ptr + delta, from, length);
9142 85702 return TYPE_OK;
9143 }
9144
9145 4483 void Field_bit_as_char::sql_type(String &res) const {
9146 4483 const CHARSET_INFO *cs = res.charset();
9147 4483 size_t length = cs->cset->snprintf(cs, res.ptr(), res.alloced_length(),
9148 4483 "bit(%d)", (int)field_length);
9149 4483 res.length(length);
9150 4483 }
9151
9152 /*****************************************************************************
9153 Handling of field and Create_field
9154 *****************************************************************************/
9155
9156 /**
9157 Calculate key length for field from its type, length and other attributes.
9158
9159 @note for string fields "length" parameter is assumed to take into account
9160 character set.
9161
9162 TODO: Get rid of this function as its code is redundant with
9163 Field::key_length() code. However creation of Field object using
9164 make_field() just to call Field::key_length() is probably overkill.
9165 */
9166
9167 73735671 uint32 calc_key_length(enum_field_types sql_type, uint32 length,
9168 uint32 decimals, bool is_unsigned, uint32 elements) {
9169 uint precision;
9170
7/7
✓ Branch 0 taken 4559650 times.
✓ Branch 1 taken 10013132 times.
✓ Branch 2 taken 10969849 times.
✓ Branch 3 taken 1811561 times.
✓ Branch 4 taken 6936 times.
✓ Branch 5 taken 38240 times.
✓ Branch 6 taken 46336303 times.
73735671 switch (sql_type) {
9171 4559650 case MYSQL_TYPE_TINY_BLOB:
9172 case MYSQL_TYPE_MEDIUM_BLOB:
9173 case MYSQL_TYPE_LONG_BLOB:
9174 case MYSQL_TYPE_BLOB:
9175 case MYSQL_TYPE_GEOMETRY:
9176 case MYSQL_TYPE_JSON:
9177 4559650 return 0;
9178 10013132 case MYSQL_TYPE_VARCHAR:
9179 10013132 return length;
9180 10969849 case MYSQL_TYPE_ENUM:
9181 10969849 return get_enum_pack_length(elements);
9182 1811561 case MYSQL_TYPE_SET:
9183 1811561 return get_set_pack_length(elements);
9184 6936 case MYSQL_TYPE_BIT:
9185
2/2
✓ Branch 0 taken 5143 times.
✓ Branch 1 taken 1793 times.
6936 return length / 8 + (length & 7 ? 1 : 0);
9186 break;
9187 38240 case MYSQL_TYPE_NEWDECIMAL:
9188 76480 precision = std::min<uint>(
9189 38240 my_decimal_length_to_precision(length, decimals, is_unsigned),
9190 38240 DECIMAL_MAX_PRECISION);
9191 38240 return my_decimal_get_binary_size(precision, decimals);
9192 46336303 default:
9193 46336303 return calc_pack_length(sql_type, length);
9194 }
9195 }
9196
9197 101356 enum_field_types get_blob_type_from_length(size_t length) {
9198 enum_field_types type;
9199
2/2
✓ Branch 0 taken 3133 times.
✓ Branch 1 taken 98223 times.
101356 if (length < 256)
9200 3133 type = MYSQL_TYPE_TINY_BLOB;
9201
2/2
✓ Branch 0 taken 89480 times.
✓ Branch 1 taken 8743 times.
98223 else if (length < 65536)
9202 89480 type = MYSQL_TYPE_BLOB;
9203
2/2
✓ Branch 0 taken 2588 times.
✓ Branch 1 taken 6155 times.
8743 else if (length < 256L * 256L * 256L)
9204 2588 type = MYSQL_TYPE_MEDIUM_BLOB;
9205 else
9206 6155 type = MYSQL_TYPE_LONG_BLOB;
9207 101356 return type;
9208 }
9209
9210 90819424 size_t calc_pack_length(enum_field_types type, size_t length) {
9211
18/26
✓ Branch 0 taken 5060470 times.
✓ Branch 1 taken 7811628 times.
✓ Branch 2 taken 4660143 times.
✓ Branch 3 taken 744208 times.
✓ Branch 4 taken 4227012 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 93002 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2604445 times.
✓ Branch 9 taken 23799436 times.
✓ Branch 10 taken 225479 times.
✓ Branch 11 taken 113258 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 732296 times.
✓ Branch 14 taken 29477285 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 60059 times.
✓ Branch 17 taken 3915081 times.
✓ Branch 18 taken 3721037 times.
✓ Branch 19 taken 2295048 times.
✓ Branch 20 taken 25452 times.
✓ Branch 21 taken 1254091 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
90819424 switch (type) {
9212 5060470 case MYSQL_TYPE_VAR_STRING:
9213 case MYSQL_TYPE_STRING:
9214 case MYSQL_TYPE_DECIMAL:
9215 5060470 return (length);
9216 7811628 case MYSQL_TYPE_VARCHAR:
9217
2/2
✓ Branch 0 taken 4222117 times.
✓ Branch 1 taken 3589511 times.
7811628 return (length + (length < 256 ? 1 : 2));
9218 4660143 case MYSQL_TYPE_BOOL:
9219 case MYSQL_TYPE_YEAR:
9220 case MYSQL_TYPE_TINY:
9221 4660143 return 1;
9222 744208 case MYSQL_TYPE_SHORT:
9223 744208 return 2;
9224 4227012 case MYSQL_TYPE_INT24:
9225 case MYSQL_TYPE_NEWDATE:
9226 4227012 return 3;
9227 case MYSQL_TYPE_TIME:
9228 return 3;
9229 93002 case MYSQL_TYPE_TIME2:
9230 return length > MAX_TIME_WIDTH
9231
2/2
✓ Branch 0 taken 37551 times.
✓ Branch 1 taken 55451 times.
93002 ? my_time_binary_length(length - MAX_TIME_WIDTH - 1)
9232 93002 : 3;
9233 case MYSQL_TYPE_TIMESTAMP:
9234 return 4;
9235 2604445 case MYSQL_TYPE_TIMESTAMP2:
9236 return length > MAX_DATETIME_WIDTH
9237
2/2
✓ Branch 0 taken 485907 times.
✓ Branch 1 taken 2118538 times.
2604445 ? my_timestamp_binary_length(length - MAX_DATETIME_WIDTH - 1)
9238 2604445 : 4;
9239 23799436 case MYSQL_TYPE_DATE:
9240 case MYSQL_TYPE_LONG:
9241 23799436 return 4;
9242 225479 case MYSQL_TYPE_FLOAT:
9243 225479 return sizeof(float);
9244 113258 case MYSQL_TYPE_DOUBLE:
9245 113258 return sizeof(double);
9246 case MYSQL_TYPE_DATETIME:
9247 return 8;
9248 732296 case MYSQL_TYPE_DATETIME2:
9249 return length > MAX_DATETIME_WIDTH
9250
2/2
✓ Branch 0 taken 7485 times.
✓ Branch 1 taken 724811 times.
732296 ? my_datetime_binary_length(length - MAX_DATETIME_WIDTH - 1)
9251 732296 : 5;
9252 29477285 case MYSQL_TYPE_LONGLONG:
9253 29477285 return 8; /* Don't crash if no longlong */
9254 case MYSQL_TYPE_NULL:
9255 return 0;
9256 60059 case MYSQL_TYPE_TINY_BLOB:
9257 60059 return 1 + portable_sizeof_char_ptr;
9258 3915081 case MYSQL_TYPE_BLOB:
9259 3915081 return 2 + portable_sizeof_char_ptr;
9260 3721037 case MYSQL_TYPE_MEDIUM_BLOB:
9261 3721037 return 3 + portable_sizeof_char_ptr;
9262 2295048 case MYSQL_TYPE_LONG_BLOB:
9263 2295048 return 4 + portable_sizeof_char_ptr;
9264 25452 case MYSQL_TYPE_GEOMETRY:
9265 25452 return 4 + portable_sizeof_char_ptr;
9266 1254091 case MYSQL_TYPE_JSON:
9267 1254091 return 4 + portable_sizeof_char_ptr;
9268 case MYSQL_TYPE_SET:
9269 case MYSQL_TYPE_ENUM:
9270 case MYSQL_TYPE_NEWDECIMAL:
9271 assert(false);
9272 return 0; // This shouldn't happen
9273 case MYSQL_TYPE_BIT:
9274 return length / 8;
9275 case MYSQL_TYPE_INVALID:
9276 case MYSQL_TYPE_TYPED_ARRAY:
9277 break;
9278 }
9279 assert(false);
9280 return 0;
9281 }
9282
9283 20777063 size_t calc_pack_length(dd::enum_column_types type, size_t char_length,
9284 size_t elements_count, bool treat_bit_as_char,
9285 uint numeric_scale, bool is_unsigned) {
9286 20777063 size_t pack_length = 0;
9287
9288
6/6
✓ Branch 0 taken 7351182 times.
✓ Branch 1 taken 3428541 times.
✓ Branch 2 taken 204701 times.
✓ Branch 3 taken 6706 times.
✓ Branch 4 taken 25804 times.
✓ Branch 5 taken 9760129 times.
20777063 switch (type) {
9289 7351182 case dd::enum_column_types::TINY_BLOB:
9290 case dd::enum_column_types::MEDIUM_BLOB:
9291 case dd::enum_column_types::LONG_BLOB:
9292 case dd::enum_column_types::BLOB:
9293 case dd::enum_column_types::GEOMETRY:
9294 case dd::enum_column_types::VAR_STRING:
9295 case dd::enum_column_types::STRING:
9296 case dd::enum_column_types::VARCHAR:
9297 // The length is already calculated in number of bytes, no need
9298 // to multiply by number of bytes per symbol.
9299 7351182 pack_length = calc_pack_length(dd_get_old_field_type(type), char_length);
9300 7351178 break;
9301 3428541 case dd::enum_column_types::ENUM:
9302 3428541 pack_length = get_enum_pack_length(elements_count);
9303 3428541 break;
9304 204701 case dd::enum_column_types::SET:
9305 204701 pack_length = get_set_pack_length(elements_count);
9306 204701 break;
9307 6706 case dd::enum_column_types::BIT: {
9308
2/2
✓ Branch 0 taken 6171 times.
✓ Branch 1 taken 535 times.
6706 if (treat_bit_as_char)
9309 6171 pack_length = ((char_length + 7) & ~7) / 8;
9310 else
9311 535 pack_length = char_length / 8;
9312 6706 } break;
9313 25804 case dd::enum_column_types::NEWDECIMAL: {
9314 25804 uint decimals = numeric_scale;
9315 25802 uint precision = std::min(
9316 25802 my_decimal_length_to_precision(char_length, decimals, is_unsigned),
9317 25804 uint(DECIMAL_MAX_PRECISION));
9318
2/4
✓ Branch 0 taken 25802 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25802 times.
✗ Branch 3 not taken.
25802 assert((precision <= DECIMAL_MAX_PRECISION) &&
9319 (decimals <= DECIMAL_MAX_SCALE));
9320 25802 pack_length = my_decimal_get_binary_size(precision, decimals);
9321 25803 } break;
9322 9760129 default:
9323 9760129 pack_length = calc_pack_length(dd_get_old_field_type(type), char_length);
9324 9760130 break;
9325 }
9326 20777059 return pack_length;
9327 }
9328
9329 43032397 Field *make_field(MEM_ROOT *mem_root, TABLE_SHARE *share, uchar *ptr,
9330 size_t field_length, uchar *null_pos, uchar null_bit,
9331 enum_field_types field_type,
9332 const CHARSET_INFO *field_charset,
9333 Field::geometry_type geom_type, uchar auto_flags,
9334 TYPELIB *interval, const char *field_name, bool is_nullable,
9335 bool is_zerofill, bool is_unsigned, uint decimals,
9336 bool treat_bit_as_char, uint pack_length_override,
9337 std::optional<gis::srid_t> srid, bool is_array) {
9338 43032397 uchar *bit_ptr = nullptr;
9339 43032397 uchar bit_offset = 0;
9340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43032397 times.
43032397 assert(mem_root);
9341
9342
4/4
✓ Branch 0 taken 14268 times.
✓ Branch 1 taken 43018129 times.
✓ Branch 2 taken 1301 times.
✓ Branch 3 taken 12967 times.
43032397 if (field_type == MYSQL_TYPE_BIT && !treat_bit_as_char) {
9343 1301 bit_ptr = null_pos;
9344 1301 bit_offset = null_bit;
9345
2/2
✓ Branch 0 taken 1164 times.
✓ Branch 1 taken 137 times.
1301 if (is_nullable) // if null field
9346 {
9347 1164 bit_ptr += (null_bit == 7); // shift bit_ptr and bit_offset
9348 1164 bit_offset = (bit_offset + 1) & 7;
9349 }
9350 }
9351
9352
2/2
✓ Branch 0 taken 27184204 times.
✓ Branch 1 taken 15848193 times.
43032397 if (!is_nullable) {
9353 27184204 null_pos = nullptr;
9354 27184204 null_bit = 0;
9355 } else {
9356 15848193 null_bit = ((uchar)1) << null_bit;
9357 }
9358
9359
2/2
✓ Branch 0 taken 1961303 times.
✓ Branch 1 taken 41071097 times.
43032397 if (is_temporal_real_type(field_type)) field_charset = &my_charset_numeric;
9360
9361
4/4
✓ Branch 0 taken 1841 times.
✓ Branch 1 taken 43030557 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 1836 times.
43032400 DBUG_PRINT("debug", ("field_type: %d, field_length: %zu, "
9362 "interval: %p, is_array: %s",
9363 field_type, field_length, interval,
9364 (is_array ? "true" : "false")));
9365
9366
2/2
✓ Branch 0 taken 2241 times.
✓ Branch 1 taken 43030149 times.
43032390 if (is_array) {
9367 // See Item_func_array_cast::resolve_type() for supported types
9368
3/4
✓ Branch 0 taken 1967 times.
✓ Branch 1 taken 168 times.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
2241 switch (field_type) {
9369 1967 case MYSQL_TYPE_VARCHAR:
9370 case MYSQL_TYPE_NEWDECIMAL:
9371 case MYSQL_TYPE_LONGLONG:
9372 case MYSQL_TYPE_NEWDATE:
9373 1967 break;
9374 168 case MYSQL_TYPE_TIME2:
9375 168 decimals = (field_length > MAX_TIME_WIDTH)
9376 168 ? field_length - 1 - MAX_TIME_WIDTH
9377 : 0;
9378 168 break;
9379 106 case MYSQL_TYPE_DATETIME2:
9380 106 decimals = (field_length > MAX_DATETIME_WIDTH)
9381 106 ? field_length - 1 - MAX_DATETIME_WIDTH
9382 : 0;
9383 106 break;
9384 case MYSQL_TYPE_YEAR:
9385 default:
9386 assert(0); // Shouldn't happen
9387 return nullptr;
9388 }
9389 /*
9390 Field_json constructor expects number of bytes used to represent length
9391 of the underlying blob as parameter and not the real field pack_length.
9392 JSON is used as array storage.
9393 */
9394 2241 uint pack_length = calc_pack_length(MYSQL_TYPE_JSON, field_length) -
9395 2241 portable_sizeof_char_ptr;
9396
9397 return new (mem_root) Field_typed_array(
9398 field_type, is_unsigned, field_length, decimals, ptr, null_pos,
9399
2/4
✓ Branch 0 taken 2241 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2241 times.
✗ Branch 3 not taken.
2241 null_bit, auto_flags, field_name, share, pack_length, field_charset);
9400 }
9401 /*
9402 FRMs from 3.23/4.0 can have strings with field_type == MYSQL_TYPE_DECIMAL.
9403 We should not be getting them after upgrade to new data-dictionary.
9404 */
9405
9406
26/27
✓ Branch 0 taken 2270873 times.
✓ Branch 1 taken 8590238 times.
✓ Branch 2 taken 5012615 times.
✓ Branch 3 taken 11920 times.
✓ Branch 4 taken 622686 times.
✓ Branch 5 taken 5416789 times.
✓ Branch 6 taken 358227 times.
✓ Branch 7 taken 1025 times.
✓ Branch 8 taken 731404 times.
✓ Branch 9 taken 188232 times.
✓ Branch 10 taken 40380 times.
✓ Branch 11 taken 1703682 times.
✓ Branch 12 taken 375149 times.
✓ Branch 13 taken 45794 times.
✓ Branch 14 taken 5187204 times.
✓ Branch 15 taken 10498795 times.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 1461152 times.
✓ Branch 18 taken 10282 times.
✓ Branch 19 taken 23128 times.
✓ Branch 20 taken 3 times.
✓ Branch 21 taken 136586 times.
✓ Branch 22 taken 22116 times.
✓ Branch 23 taken 307595 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 14268 times.
✓ Branch 26 taken 2 times.
43030149 switch (field_type) {
9407 2270873 case MYSQL_TYPE_VAR_STRING:
9408 case MYSQL_TYPE_STRING:
9409 return new (mem_root) Field_string(ptr, field_length, null_pos, null_bit,
9410
2/4
✓ Branch 0 taken 2270875 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2270875 times.
✗ Branch 3 not taken.
2270873 auto_flags, field_name, field_charset);
9411 8590238 case MYSQL_TYPE_VARCHAR:
9412 return new (mem_root) Field_varstring(
9413 ptr, field_length, HA_VARCHAR_PACKLENGTH(field_length), null_pos,
9414
4/6
✓ Branch 0 taken 8590240 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4459144 times.
✓ Branch 3 taken 4131096 times.
✓ Branch 4 taken 8590242 times.
✗ Branch 5 not taken.
8590238 null_bit, auto_flags, field_name, share, field_charset);
9415 5012615 case MYSQL_TYPE_BLOB:
9416 case MYSQL_TYPE_MEDIUM_BLOB:
9417 case MYSQL_TYPE_TINY_BLOB:
9418 case MYSQL_TYPE_LONG_BLOB: {
9419 /*
9420 Field_blob constructor expects number of bytes used to represent length
9421 of the blob as parameter and not the real field pack_length.
9422 */
9423 uint pack_length =
9424 5012615 calc_pack_length(field_type, field_length) - portable_sizeof_char_ptr;
9425
9426 return new (mem_root)
9427 Field_blob(ptr, null_pos, null_bit, auto_flags, field_name, share,
9428
2/4
✓ Branch 0 taken 5012616 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5012611 times.
✗ Branch 3 not taken.
5012615 pack_length, field_charset);
9429 }
9430 11920 case MYSQL_TYPE_GEOMETRY: {
9431 /*
9432 Field_geom constructor expects number of bytes used to represent length
9433 of the underlying blob as parameter and not the real field pack_length.
9434 */
9435 uint pack_length =
9436 11920 calc_pack_length(field_type, field_length) - portable_sizeof_char_ptr;
9437
9438 return new (mem_root)
9439 Field_geom(ptr, null_pos, null_bit, auto_flags, field_name, share,
9440
2/4
✓ Branch 0 taken 11920 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11920 times.
✗ Branch 3 not taken.
11920 pack_length, geom_type, srid);
9441 }
9442 622686 case MYSQL_TYPE_JSON: {
9443 /*
9444 Field_json constructor expects number of bytes used to represent length
9445 of the underlying blob as parameter and not the real field pack_length.
9446 */
9447 uint pack_length =
9448 622686 calc_pack_length(field_type, field_length) - portable_sizeof_char_ptr;
9449
9450 return new (mem_root) Field_json(ptr, null_pos, null_bit, auto_flags,
9451
2/4
✓ Branch 0 taken 622686 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 622686 times.
✗ Branch 3 not taken.
622686 field_name, share, pack_length);
9452 }
9453 5416789 case MYSQL_TYPE_ENUM:
9454
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5416789 times.
5416789 assert(interval);
9455 return new (mem_root) Field_enum(
9456 ptr, field_length, null_pos, null_bit, auto_flags, field_name,
9457
2/2
✓ Branch 0 taken 5416788 times.
✓ Branch 1 taken 1 times.
5416789 (pack_length_override ? pack_length_override
9458 5416788 : get_enum_pack_length(interval->count)),
9459
2/4
✓ Branch 0 taken 5416789 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5416789 times.
✗ Branch 3 not taken.
5416789 interval, field_charset);
9460 358227 case MYSQL_TYPE_SET:
9461
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 358227 times.
358227 assert(interval);
9462 return new (mem_root) Field_set(
9463 ptr, field_length, null_pos, null_bit, auto_flags, field_name,
9464
2/2
✓ Branch 0 taken 358220 times.
✓ Branch 1 taken 7 times.
358227 (pack_length_override ? pack_length_override
9465 358220 : get_set_pack_length(interval->count)),
9466
2/4
✓ Branch 0 taken 358227 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 358227 times.
✗ Branch 3 not taken.
358227 interval, field_charset);
9467 1025 case MYSQL_TYPE_DECIMAL:
9468 return new (mem_root)
9469 Field_decimal(ptr, field_length, null_pos, null_bit, auto_flags,
9470
2/4
✓ Branch 0 taken 1025 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1025 times.
✗ Branch 3 not taken.
1025 field_name, decimals, is_zerofill, is_unsigned);
9471 731404 case MYSQL_TYPE_NEWDECIMAL:
9472 return new (mem_root)
9473 Field_new_decimal(ptr, field_length, null_pos, null_bit, auto_flags,
9474
2/4
✓ Branch 0 taken 731404 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 731407 times.
✗ Branch 3 not taken.
731404 field_name, decimals, is_zerofill, is_unsigned);
9475 188232 case MYSQL_TYPE_FLOAT:
9476 return new (mem_root)
9477 Field_float(ptr, field_length, null_pos, null_bit, auto_flags,
9478
2/4
✓ Branch 0 taken 188232 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 188232 times.
✗ Branch 3 not taken.
188232 field_name, decimals, is_zerofill, is_unsigned);
9479 40380 case MYSQL_TYPE_DOUBLE:
9480 return new (mem_root)
9481 Field_double(ptr, field_length, null_pos, null_bit, auto_flags,
9482
2/4
✓ Branch 0 taken 40380 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40380 times.
✗ Branch 3 not taken.
40380 field_name, decimals, is_zerofill, is_unsigned);
9483 1703682 case MYSQL_TYPE_TINY:
9484 return new (mem_root)
9485 Field_tiny(ptr, field_length, null_pos, null_bit, auto_flags,
9486
2/4
✓ Branch 0 taken 1703682 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1703682 times.
✗ Branch 3 not taken.
1703682 field_name, is_zerofill, is_unsigned);
9487 375149 case MYSQL_TYPE_SHORT:
9488 return new (mem_root)
9489 Field_short(ptr, field_length, null_pos, null_bit, auto_flags,
9490
2/4
✓ Branch 0 taken 375149 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 375149 times.
✗ Branch 3 not taken.
375149 field_name, is_zerofill, is_unsigned);
9491 45794 case MYSQL_TYPE_INT24:
9492 return new (mem_root)
9493 Field_medium(ptr, field_length, null_pos, null_bit, auto_flags,
9494
2/4
✓ Branch 0 taken 45794 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45794 times.
✗ Branch 3 not taken.
45794 field_name, is_zerofill, is_unsigned);
9495 5187204 case MYSQL_TYPE_LONG:
9496 return new (mem_root)
9497 Field_long(ptr, field_length, null_pos, null_bit, auto_flags,
9498
2/4
✓ Branch 0 taken 5187211 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5187209 times.
✗ Branch 3 not taken.
5187204 field_name, is_zerofill, is_unsigned);
9499 10498795 case MYSQL_TYPE_LONGLONG:
9500 return new (mem_root)
9501 Field_longlong(ptr, field_length, null_pos, null_bit, auto_flags,
9502
2/4
✓ Branch 0 taken 10498795 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10498795 times.
✗ Branch 3 not taken.
10498795 field_name, is_zerofill, is_unsigned);
9503 4 case MYSQL_TYPE_TIMESTAMP:
9504 return new (mem_root) Field_timestamp(ptr, field_length, null_pos,
9505
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 null_bit, auto_flags, field_name);
9506 1461152 case MYSQL_TYPE_TIMESTAMP2:
9507 return new (mem_root)
9508 Field_timestampf(ptr, null_pos, null_bit, auto_flags, field_name,
9509 field_length > MAX_DATETIME_WIDTH
9510 1461152 ? field_length - 1 - MAX_DATETIME_WIDTH
9511
2/4
✓ Branch 0 taken 1461152 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1461152 times.
✗ Branch 3 not taken.
1461152 : 0);
9512 10282 case MYSQL_TYPE_YEAR:
9513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10282 times.
10282 assert(field_length == 4); // Field_year is only for length 4.
9514 return new (mem_root)
9515
2/4
✓ Branch 0 taken 10282 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10282 times.
✗ Branch 3 not taken.
10282 Field_year(ptr, null_pos, null_bit, auto_flags, field_name);
9516 23128 case MYSQL_TYPE_NEWDATE:
9517 return new (mem_root)
9518
2/4
✓ Branch 0 taken 23128 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23128 times.
✗ Branch 3 not taken.
23128 Field_newdate(ptr, null_pos, null_bit, auto_flags, field_name);
9519
9520 3 case MYSQL_TYPE_TIME:
9521 return new (mem_root)
9522
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 Field_time(ptr, null_pos, null_bit, auto_flags, field_name);
9523 136586 case MYSQL_TYPE_TIME2:
9524 return new (mem_root) Field_timef(
9525 ptr, null_pos, null_bit, auto_flags, field_name,
9526 136586 (field_length > MAX_TIME_WIDTH) ? field_length - 1 - MAX_TIME_WIDTH
9527
2/4
✓ Branch 0 taken 136586 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136586 times.
✗ Branch 3 not taken.
136586 : 0);
9528 22116 case MYSQL_TYPE_DATETIME:
9529 return new (mem_root)
9530
2/4
✓ Branch 0 taken 22116 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22116 times.
✗ Branch 3 not taken.
22116 Field_datetime(ptr, null_pos, null_bit, auto_flags, field_name);
9531 307595 case MYSQL_TYPE_DATETIME2:
9532 return new (mem_root)
9533 Field_datetimef(ptr, null_pos, null_bit, auto_flags, field_name,
9534 (field_length > MAX_DATETIME_WIDTH)
9535 307595 ? field_length - 1 - MAX_DATETIME_WIDTH
9536
2/4
✓ Branch 0 taken 307595 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 307598 times.
✗ Branch 3 not taken.
307595 : 0);
9537 case MYSQL_TYPE_NULL:
9538 return new (mem_root)
9539 Field_null(ptr, field_length, auto_flags, field_name, field_charset);
9540 14268 case MYSQL_TYPE_BIT:
9541 return treat_bit_as_char
9542
4/6
✓ Branch 0 taken 12967 times.
✓ Branch 1 taken 1301 times.
✓ Branch 2 taken 12967 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1301 times.
✗ Branch 5 not taken.
42804 ? new (mem_root)
9543 Field_bit_as_char(ptr, field_length, null_pos, null_bit,
9544
1/2
✓ Branch 0 taken 12967 times.
✗ Branch 1 not taken.
25934 auto_flags, field_name)
9545 : new (mem_root)
9546 Field_bit(ptr, field_length, null_pos, null_bit, bit_ptr,
9547
1/2
✓ Branch 0 taken 1301 times.
✗ Branch 1 not taken.
16870 bit_offset, auto_flags, field_name);
9548
9549 2 case MYSQL_TYPE_INVALID:
9550 case MYSQL_TYPE_BOOL:
9551 default: // Impossible (Wrong version)
9552 2 break;
9553 }
9554 2 return nullptr;
9555 }
9556
9557 22654892 Field *make_field(const Create_field &create_field, TABLE_SHARE *share,
9558 const char *field_name, size_t field_length, uchar *ptr,
9559 uchar *null_pos, size_t null_bit) {
9560 22654891 return make_field(*THR_MALLOC, share, ptr, field_length, null_pos, null_bit,
9561 22654892 create_field.sql_type, create_field.charset,
9562 22654892 create_field.geom_type, create_field.auto_flags,
9563 22654892 create_field.interval, field_name, create_field.is_nullable,
9564 22654892 create_field.is_zerofill, create_field.is_unsigned,
9565 22654892 create_field.decimals, create_field.treat_bit_as_char,
9566 22654892 create_field.pack_length_override, create_field.m_srid,
9567 45309781 create_field.is_array);
9568 }
9569
9570 14402887 Field *make_field(const Create_field &create_field, TABLE_SHARE *share,
9571 uchar *ptr, uchar *null_pos, size_t null_bit) {
9572 14402887 return make_field(create_field, share, create_field.field_name,
9573 create_field.max_display_width_in_bytes(), ptr, null_pos,
9574 14402889 null_bit);
9575 }
9576
9577 8128239 Field *make_field(const Create_field &create_field, TABLE_SHARE *share) {
9578 8128239 return make_field(create_field, share, create_field.field_name,
9579 create_field.max_display_width_in_bytes(), nullptr, nullptr,
9580 8128241 0);
9581 }
9582
9583 /**
9584 maximum possible character length for blob.
9585
9586 This method is used in Item_field::set_field to calculate
9587 max_length for Item.
9588
9589 For example:
9590 CREATE TABLE t2 SELECT CONCAT(tinyblob_utf8_column) FROM t1;
9591 must create a "VARCHAR(255) CHARACTER SET utf8" column.
9592
9593 @return
9594 length
9595 */
9596
9597 4747201 uint32 Field_blob::char_length() const noexcept {
9598
4/5
✓ Branch 0 taken 54185 times.
✓ Branch 1 taken 1698596 times.
✓ Branch 2 taken 2175984 times.
✓ Branch 3 taken 818444 times.
✗ Branch 4 not taken.
4747201 switch (packlength) {
9599 54185 case 1:
9600 54185 return 255;
9601 1698596 case 2:
9602 1698596 return 65535;
9603 2175984 case 3:
9604 2175984 return 16777215;
9605 818444 case 4:
9606 818444 return (uint32)4294967295U;
9607 default:
9608 assert(0); // we should never go here
9609 return 0;
9610 }
9611 }
9612
9613 /**
9614 This function creates a separate copy of blob value.
9615
9616 @param [in] mem_root
9617 mem_root that is used to allocate memory for 'copy_of_value'.
9618
9619 @return - Can fail if we are out of memory.
9620 @retval false Success
9621 @retval true Failure
9622 */
9623
9624 1007 bool Field_blob::copy_blob_value(MEM_ROOT *mem_root) {
9625
1/2
✓ Branch 0 taken 1007 times.
✗ Branch 1 not taken.
1007 DBUG_TRACE;
9626
9627 // Testing memory allocation failure
9628
2/6
✓ Branch 0 taken 1007 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1007 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1007 DBUG_EXECUTE_IF("simulate_blob_memory_allocation_fail",
9629 DBUG_SET("+d,simulate_out_of_memory"););
9630
9631 // Allocate new memory location
9632
1/2
✓ Branch 0 taken 1007 times.
✗ Branch 1 not taken.
1007 size_t ulen = get_length(ptr);
9633
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1006 times.
1007 if (ulen == 0) {
9634
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 value.set("", 0, value.charset());
9635 } else {
9636 char *blob_value =
9637
2/4
✓ Branch 0 taken 1006 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1006 times.
✗ Branch 3 not taken.
1006 static_cast<char *>(memdup_root(mem_root, get_blob_data(), ulen));
9638
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1006 times.
1006 if (blob_value == nullptr) return true;
9639
9640 // Set 'value' with the duplicated data
9641
1/2
✓ Branch 0 taken 1006 times.
✗ Branch 1 not taken.
1006 value.set(blob_value, ulen, value.charset());
9642 }
9643
9644 // Set ptr of Field for duplicated data
9645
1/2
✓ Branch 0 taken 1007 times.
✗ Branch 1 not taken.
1007 store_ptr_and_length(value.ptr(), ulen);
9646
9647 1007 return false;
9648 1007 }
9649
9650 /**
9651 maximum possible display length for blob.
9652
9653 @return
9654 length
9655 */
9656
9657 4488734 uint32 Field_blob::max_display_length() const {
9658
4/5
✓ Branch 0 taken 51811 times.
✓ Branch 1 taken 1507967 times.
✓ Branch 2 taken 2162446 times.
✓ Branch 3 taken 766519 times.
✗ Branch 4 not taken.
4488734 switch (packlength) {
9659 51811 case 1:
9660 51811 return 255 * field_charset->mbmaxlen;
9661 1507967 case 2:
9662 1507967 return 65535 * field_charset->mbmaxlen;
9663 2162446 case 3:
9664 2162446 return 16777215 * field_charset->mbmaxlen;
9665 766519 case 4:
9666 766519 return (uint32)4294967295U;
9667 default:
9668 assert(0); // we should never go here
9669 return 0;
9670 }
9671 }
9672
9673 /*****************************************************************************
9674 Warning handling
9675 *****************************************************************************/
9676
9677 /**
9678 Produce warning or note about data saved into field.
9679
9680 @param level - level of message (Note/Warning/Error)
9681 @param code - error code of message to be produced
9682 @param truncate_increment - whether we should increase truncated fields
9683 count
9684 @param view_db_name - if set this is the database name for view
9685 that causes the warning
9686 @param view_name - if set this is the name of view that causes
9687 the warning
9688
9689 @note
9690 This function won't produce warning and increase cut fields counter
9691 if check_for_truncated_fields == CHECK_FIELD_IGNORE for current thread.
9692
9693 if check_for_truncated_fields == CHECK_FIELD_IGNORE then we ignore notes.
9694 This allows us to avoid notes in optimisation, like convert_constant_item().
9695
9696 In case of execution statements INSERT/INSERT SELECT/REPLACE/REPLACE SELECT
9697 the method emits only one warning message for the following
9698 types of warning: ER_BAD_NULL_ERROR, ER_WARN_NULL_TO_NOTNULL,
9699 ER_NO_DEFAULT_FOR_FIELD.
9700 @retval
9701 1 if check_for_truncated_fields == CHECK_FIELD_IGNORE and error level
9702 is not NOTE
9703 @retval
9704 0 otherwise
9705 */
9706
9707 270212 bool Field::set_warning(Sql_condition::enum_severity_level level, uint code,
9708 int truncate_increment, const char *view_db_name,
9709 const char *view_name) {
9710 /*
9711 If this field was created only for type conversion purposes it
9712 will have table == NULL.
9713 */
9714
9715 270212 THD *thd = current_thd;
9716
9717
2/2
✓ Branch 0 taken 147691 times.
✓ Branch 1 taken 122521 times.
270212 if (!thd->check_for_truncated_fields)
9718 147691 return level >= Sql_condition::SL_WARNING;
9719
9720 122521 thd->num_truncated_fields += truncate_increment;
9721
9722
2/2
✓ Branch 0 taken 101119 times.
✓ Branch 1 taken 21402 times.
122521 if (thd->lex->sql_command != SQLCOM_INSERT &&
9723
2/2
✓ Branch 0 taken 7267 times.
✓ Branch 1 taken 93852 times.
101119 thd->lex->sql_command != SQLCOM_INSERT_SELECT &&
9724
2/2
✓ Branch 0 taken 7212 times.
✓ Branch 1 taken 55 times.
7267 thd->lex->sql_command != SQLCOM_REPLACE &&
9725
2/2
✓ Branch 0 taken 7096 times.
✓ Branch 1 taken 116 times.
7212 thd->lex->sql_command != SQLCOM_REPLACE_SELECT) {
9726 // We aggregate warnings from only INSERT and REPLACE statements.
9727
9728 7096 push_warning_printf(thd, level, code, ER_THD_NONCONST(thd, code),
9729 field_name,
9730 thd->get_stmt_da()->current_row_for_condition());
9731
9732 7096 return false;
9733 }
9734
9735 115425 unsigned int current_warning_mask = 0;
9736
9737
2/2
✓ Branch 0 taken 417 times.
✓ Branch 1 taken 115008 times.
115425 if (code == ER_BAD_NULL_ERROR)
9738 417 current_warning_mask = BAD_NULL_ERROR_PUSHED;
9739
2/2
✓ Branch 0 taken 1813 times.
✓ Branch 1 taken 113195 times.
115008 else if (code == ER_NO_DEFAULT_FOR_FIELD)
9740 1813 current_warning_mask = NO_DEFAULT_FOR_FIELD_PUSHED;
9741
9742
2/2
✓ Branch 0 taken 2230 times.
✓ Branch 1 taken 113195 times.
115425 if (current_warning_mask) {
9743
2/2
✓ Branch 0 taken 1145 times.
✓ Branch 1 taken 1085 times.
2230 if (!(m_warnings_pushed & current_warning_mask)) {
9744 1145 push_warning_printf(thd, level, code, ER_THD_NONCONST(thd, code),
9745 field_name,
9746 thd->get_stmt_da()->current_row_for_condition());
9747 1145 m_warnings_pushed |= current_warning_mask;
9748 }
9749
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 113056 times.
113195 } else if (code == ER_NO_DEFAULT_FOR_VIEW_FIELD) {
9750
2/2
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 52 times.
139 if (!(m_warnings_pushed & NO_DEFAULT_FOR_VIEW_FIELD_PUSHED)) {
9751 87 push_warning_printf(
9752 thd, Sql_condition::SL_WARNING, ER_NO_DEFAULT_FOR_VIEW_FIELD,
9753 ER_THD(thd, ER_NO_DEFAULT_FOR_VIEW_FIELD), view_db_name, view_name);
9754 87 m_warnings_pushed |= NO_DEFAULT_FOR_VIEW_FIELD_PUSHED;
9755 }
9756 } else {
9757 113056 push_warning_printf(thd, level, code, ER_THD_NONCONST(thd, code),
9758 field_name,
9759 thd->get_stmt_da()->current_row_for_condition());
9760 }
9761
9762 115425 return false;
9763 }
9764
9765 5645 bool Field_temporal::set_datetime_warning(
9766 Sql_condition::enum_severity_level level, uint code,
9767 const ErrConvString &val, enum_mysql_timestamp_type ts_type,
9768 int truncate_increment) {
9769 5645 THD *thd = current_thd;
9770 5645 if ((!thd->lex->is_ignore() &&
9771
2/2
✓ Branch 0 taken 2901 times.
✓ Branch 1 taken 150 times.
3051 ((thd->variables.sql_mode & MODE_STRICT_ALL_TABLES) ||
9772
2/2
✓ Branch 0 taken 693 times.
✓ Branch 1 taken 2208 times.
2901 (thd->variables.sql_mode & MODE_STRICT_TRANS_TABLES &&
9773
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 690 times.
693 !thd->get_transaction()->cannot_safely_rollback(
9774
4/4
✓ Branch 0 taken 3051 times.
✓ Branch 1 taken 2594 times.
✓ Branch 2 taken 1355 times.
✓ Branch 3 taken 4290 times.
11290 Transaction_ctx::STMT)))) ||
9775
2/2
✓ Branch 0 taken 515 times.
✓ Branch 1 taken 4290 times.
4805 set_warning(level, code, truncate_increment))
9776 1355 return make_truncated_value_warning(thd, level, val, ts_type, field_name);
9777
9778 4290 return false;
9779 }
9780
9781 381 bool Field::is_part_of_actual_key(THD *thd, uint cur_index,
9782 KEY *cur_index_info) const {
9783 381 return thd->optimizer_switch_flag(OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS) &&
9784
2/2
✓ Branch 0 taken 290 times.
✓ Branch 1 taken 75 times.
365 !(cur_index_info->flags & HA_NOSAME)
9785
2/2
✓ Branch 0 taken 365 times.
✓ Branch 1 taken 16 times.
671 ? part_of_key.is_set(cur_index)
9786 381 : part_of_key_not_extended.is_set(cur_index);
9787 }
9788
9789 1052 Field_typed_array::Field_typed_array(const Field_typed_array &other)
9790 : Field_json(other),
9791 1052 m_elt_type(other.m_elt_type),
9792 1052 m_elt_decimals(other.m_elt_decimals),
9793 1052 m_elt_charset(other.m_elt_charset),
9794 1052 unsigned_flag(other.is_unsigned()) {}
9795
9796 2512 Field_typed_array::Field_typed_array(
9797 enum_field_types elt_type, bool elt_is_unsigned, size_t elt_length,
9798 uint elt_decimals, uchar *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg,
9799 uchar auto_flags_arg, const char *field_name_arg, TABLE_SHARE *share,
9800 2512 uint blob_pack_length, const CHARSET_INFO *cs)
9801 : Field_json(ptr_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
9802 field_name_arg, share, blob_pack_length),
9803 2512 m_elt_type(elt_type),
9804 2512 m_elt_decimals(elt_decimals),
9805 2512 m_elt_charset(cs),
9806 2512 unsigned_flag(elt_is_unsigned) {
9807
2/2
✓ Branch 0 taken 684 times.
✓ Branch 1 taken 1828 times.
2512 if (elt_is_unsigned) set_flag(UNSIGNED_FLAG);
9808
2/2
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 508 times.
2512 if (Field_typed_array::binary()) set_flag(BINARY_FLAG);
9809 2512 field_length = elt_length;
9810 /*
9811 Arrays of BLOB aren't supported and can't be created, so mask the BLOB
9812 flag of JSON
9813 */
9814 2512 clear_flag(BLOB_FLAG);
9815
2/4
✓ Branch 0 taken 2512 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2512 times.
✗ Branch 3 not taken.
2512 assert(elt_type != MYSQL_TYPE_STRING && elt_type != MYSQL_TYPE_VAR_STRING);
9816 2512 }
9817
9818 86828 uint32 Field_typed_array::key_length() const {
9819 86828 return calc_key_length(m_elt_type, field_length, m_elt_decimals,
9820 86828 is_unsigned(),
9821 // Number of intervals isn't applicable here
9822 86828 0);
9823 }
9824
9825 1052 Field_typed_array *Field_typed_array::clone(MEM_ROOT *mem_root) const {
9826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1052 times.
1052 assert(is_array());
9827
2/4
✓ Branch 0 taken 1052 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1052 times.
✗ Branch 3 not taken.
1052 return new (mem_root) Field_typed_array(*this);
9828 }
9829
9830 7420 Item_result Field_typed_array::result_type() const {
9831 7420 return field_types_result_type[field_type2index(m_elt_type)];
9832 }
9833
9834 type_conversion_status Field_typed_array::store(const char *to, size_t length,
9835 const CHARSET_INFO *charset) {
9836 return m_conv_item->field->store(to, length, charset);
9837 }
9838
9839 type_conversion_status Field_typed_array::store(double nr) {
9840 return m_conv_item->field->store(nr);
9841 }
9842
9843 type_conversion_status Field_typed_array::store(longlong nr,
9844 bool unsigned_val) {
9845 return m_conv_item->field->store(nr, unsigned_val);
9846 }
9847
9848 28171 type_conversion_status Field_typed_array::store_array(const Json_wrapper *data,
9849 Json_array *array) {
9850 28171 array->clear();
9851
9852 28171 set_null();
9853
9854 try {
9855 // How to store values
9856
6/9
✓ Branch 0 taken 28171 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 104 times.
✓ Branch 4 taken 28054 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
28171 switch (data->type()) {
9857 11 case enum_json_type::J_NULL: {
9858 /*
9859 Unlike SQL NULL, JSON null is a value, but a special one and it
9860 can't be coerced to any data type. The latter means it can't be
9861 indexed by relational SE. Due to that an error is thrown.
9862 */
9863
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 my_error(ER_INVALID_JSON_VALUE_FOR_FUNC_INDEX, MYF(0),
9864 get_index_name());
9865 11 return TYPE_ERR_BAD_VALUE;
9866 }
9867 104 case enum_json_type::J_DECIMAL:
9868 case enum_json_type::J_DOUBLE:
9869 case enum_json_type::J_STRING:
9870 case enum_json_type::J_DATE:
9871 case enum_json_type::J_TIME:
9872 case enum_json_type::J_DATETIME:
9873 case enum_json_type::J_TIMESTAMP:
9874 case enum_json_type::J_INT:
9875 case enum_json_type::J_UINT: {
9876 // Handle scalars
9877 104 Json_wrapper coerced;
9878
3/4
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 101 times.
104 if (coerce_json_value(data, false, &coerced))
9879 3 return TYPE_ERR_BAD_VALUE; /* purecov: inspected */
9880 101 coerced.set_alias();
9881
3/6
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 101 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 101 times.
101 if (array->append_alias(coerced.to_dom())) {
9882 return TYPE_ERR_OOM;
9883 }
9884
1/2
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
101 Json_wrapper wr(array, true);
9885 /*
9886 No need to check multi-valued key limits, as single value is always
9887 allowed if engine supports multi-valued index, and single value
9888 can't outgrow index length limit.
9889 */
9890
1/2
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
101 set_notnull();
9891
1/2
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
101 return store_json(&wr);
9892 104 }
9893 28054 case enum_json_type::J_ARRAY: {
9894 // Handle array
9895 28054 Json_wrapper coerced;
9896 28054 uint max_num_keys = 0;
9897 28054 size_t keys_length = 0, max_keys_length = 0;
9898
9899 // Empty array stored as non-NULL empty array
9900
3/4
✓ Branch 0 taken 28054 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 28016 times.
28054 if (data->length() == 0) {
9901
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 Json_wrapper wr(array, true);
9902
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 set_notnull();
9903
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 return store_json(&wr);
9904 38 }
9905
1/2
✓ Branch 0 taken 28016 times.
✗ Branch 1 not taken.
28016 table->file->ha_mv_key_capacity(&max_num_keys, &max_keys_length);
9906
2/4
✓ Branch 0 taken 28016 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28016 times.
✗ Branch 3 not taken.
28016 assert(max_num_keys && max_keys_length);
9907
3/4
✓ Branch 0 taken 357632 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329642 times.
✓ Branch 3 taken 27990 times.
357632 for (size_t i = 0; i < data->length(); i++) {
9908
1/2
✓ Branch 0 taken 329642 times.
✗ Branch 1 not taken.
329642 Json_wrapper elt = (*data)[i];
9909
3/4
✓ Branch 0 taken 329642 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 329634 times.
329642 if (elt.type() == enum_json_type::J_NULL) {
9910 /*
9911 Unlike SQL NULL, JSON null is a value, but a special one and it
9912 can't be coerced to any data type. The latter means it can't be
9913 indexed by relational SE. Due to that an error is thrown.
9914 */
9915
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 my_error(ER_INVALID_JSON_VALUE_FOR_FUNC_INDEX, MYF(0),
9916 get_index_name());
9917 8 return TYPE_ERR_BAD_VALUE;
9918 }
9919
9920
3/4
✓ Branch 0 taken 329634 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 329616 times.
329634 if (coerce_json_value(&elt, false, &coerced))
9921 18 return TYPE_ERR_BAD_VALUE;
9922 329616 coerced.set_alias();
9923
3/6
✓ Branch 0 taken 329616 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 329616 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 329616 times.
329616 if (array->append_alias(coerced.to_dom())) {
9924 return TYPE_ERR_OOM;
9925 }
9926
2/2
✓ Branch 0 taken 69235 times.
✓ Branch 1 taken 260381 times.
329616 if (type() == MYSQL_TYPE_VARCHAR)
9927
1/2
✓ Branch 0 taken 69235 times.
✗ Branch 1 not taken.
69235 keys_length += coerced.get_data_length();
9928 else
9929
1/2
✓ Branch 0 taken 260381 times.
✗ Branch 1 not taken.
260381 keys_length += m_conv_item->field->pack_length();
9930
2/2
✓ Branch 0 taken 329616 times.
✓ Branch 1 taken 26 times.
329642 }
9931 /*
9932 Non-strict mode issue:
9933 While consisting of unique values, bad input can cause duplicates
9934 after coercion. Remove them, as SE doesn't expect dups in the array.
9935 This is why we need to sort & remove duplicates only after
9936 processing all keys.
9937 */
9938
2/2
✓ Branch 0 taken 27601 times.
✓ Branch 1 taken 389 times.
27990 if (array->size() > 1)
9939
3/4
✓ Branch 0 taken 615 times.
✓ Branch 1 taken 26986 times.
✓ Branch 2 taken 27601 times.
✗ Branch 3 not taken.
27601 array->remove_duplicates(type() == MYSQL_TYPE_VARCHAR ? m_elt_charset
9940 : nullptr);
9941
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 27988 times.
27990 if (array->size() > max_num_keys) {
9942
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 my_error(ER_EXCEEDED_MV_KEYS_NUM, MYF(0), get_index_name(),
9943
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 array->size() - max_num_keys);
9944 2 return TYPE_ERR_BAD_VALUE;
9945 }
9946
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 27987 times.
27988 if (keys_length > max_keys_length) {
9947 // Array fields have only one index defined over them
9948
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 my_error(ER_EXCEEDED_MV_KEYS_SPACE, MYF(0), get_index_name(),
9949 (keys_length - max_keys_length));
9950 1 return TYPE_ERR_BAD_VALUE;
9951 }
9952
1/2
✓ Branch 0 taken 27987 times.
✗ Branch 1 not taken.
27987 Json_wrapper wr(array, true);
9953
1/2
✓ Branch 0 taken 27987 times.
✗ Branch 1 not taken.
27987 set_notnull();
9954
1/2
✓ Branch 0 taken 27987 times.
✗ Branch 1 not taken.
27987 return store_json(&wr);
9955 28054 }
9956 1 case enum_json_type::J_BOOLEAN: {
9957
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 my_error(ER_NOT_SUPPORTED_YET, MYF(0),
9958 "CAST-ing JSON BOOLEAN type to array");
9959 1 return TYPE_ERR_BAD_VALUE;
9960 }
9961
9962 1 case enum_json_type::J_OBJECT: {
9963
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 my_error(ER_NOT_SUPPORTED_YET, MYF(0),
9964 "CAST-ing JSON OBJECT type to array");
9965 1 return TYPE_ERR_BAD_VALUE;
9966 }
9967 case enum_json_type::J_ERROR:
9968 my_error(ER_INVALID_JSON_VALUE_FOR_FUNC_INDEX, MYF(0),
9969 get_index_name());
9970 return TYPE_ERR_BAD_VALUE;
9971 /* purecov: begin inspected */
9972 default:
9973 // Shouldn't happen
9974 assert(0);
9975 return TYPE_ERR_BAD_VALUE;
9976 }
9977 } catch (...) {
9978 handle_std_exception("typed array field");
9979 }
9980 return TYPE_ERR_BAD_VALUE;
9981 /* purecov: end */
9982 }
9983
9984 765 size_t Field_typed_array::get_key_image(uchar *buff, size_t length,
9985 imagetype type) const {
9986 765 return m_conv_item->field->get_key_image(buff, length, type);
9987 }
9988
9989 35 Field *Field_typed_array::get_conv_field() { return m_conv_item->field; }
9990
9991 374 Field *Field_typed_array::new_key_field(MEM_ROOT *root, TABLE *new_table,
9992 uchar *new_ptr, uchar *, uint) const {
9993 374 Field *res = m_conv_item->field->new_key_field(root, new_table, new_ptr);
9994
1/2
✓ Branch 0 taken 374 times.
✗ Branch 1 not taken.
374 if (res != nullptr) {
9995 // Keep the field hidden to allow error handler to catch functional
9996 // index's errors
9997 374 res->set_hidden(dd::Column::enum_hidden_type::HT_HIDDEN_SQL);
9998 374 res->part_of_key = part_of_key;
9999 }
10000 374 return res;
10001 }
10002
10003 2589 void Field_typed_array::init(TABLE *table_arg) {
10004
1/2
✓ Branch 0 taken 2589 times.
✗ Branch 1 not taken.
2589 Field::init(table_arg);
10005
10006
1/2
✓ Branch 0 taken 2589 times.
✗ Branch 1 not taken.
2589 switch (type()) {
10007 2589 case MYSQL_TYPE_VARCHAR:
10008 case MYSQL_TYPE_TIME:
10009 case MYSQL_TYPE_DATETIME:
10010 case MYSQL_TYPE_TIMESTAMP:
10011 case MYSQL_TYPE_DATE:
10012 case MYSQL_TYPE_LONG:
10013 case MYSQL_TYPE_LONGLONG:
10014 case MYSQL_TYPE_NEWDECIMAL:
10015 2589 break;
10016 case MYSQL_TYPE_YEAR:
10017 default:
10018 // Shouldn't happen
10019 assert(0); /* purecov: inspected */
10020 return;
10021 }
10022
10023 // Set mem_root for conversion field allocation.
10024 2589 MEM_ROOT *actual_mem_root =
10025 2589 (table_arg->s->table_category == TABLE_CATEGORY_TEMPORARY)
10026
2/2
✓ Branch 0 taken 272 times.
✓ Branch 1 taken 2317 times.
2589 ? &table_arg->s->mem_root
10027 : &table_arg->mem_root;
10028 // Create field for data conversion
10029 5178 Field *conv_field = ::make_field(
10030 // Allocate conversion field in table's mem_root for non-temp
10031 // tables. Allocate conversion field in TABLE_SHARE's mem_root
10032 // for internal temporary tables.
10033 actual_mem_root,
10034 nullptr, // TABLE_SHARE, not needed
10035 nullptr, // data buffer, isn't allocated yet
10036
1/2
✓ Branch 0 taken 2589 times.
✗ Branch 1 not taken.
2589 field_length, // field_length
10037 nullptr, 0, // null_pos, nul_bit
10038 real_type(), // field_type
10039 m_elt_charset,
10040 Field::GEOM_GEOMETRY, // geom type
10041 Field::NONE, // auto_flags
10042 nullptr, // intervals aren't supported in array
10043 2589 field_name, is_nullable(),
10044 false, // zerofill is meaningless with JSON
10045 2589 is_unsigned(), m_elt_decimals,
10046 false, // treat_bit_as_char
10047 0, // pack_length_override
10048 {}, // srid
10049 false // is_array
10050 );
10051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2589 times.
2589 if (conv_field == nullptr) return;
10052 uchar *buf =
10053
2/4
✓ Branch 0 taken 2589 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2589 times.
✗ Branch 3 not taken.
2589 actual_mem_root->ArrayAlloc<uchar>(conv_field->pack_length() + 1);
10054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2589 times.
2589 if (buf == nullptr) return;
10055
2/2
✓ Branch 0 taken 282 times.
✓ Branch 1 taken 2307 times.
2589 if (type() == MYSQL_TYPE_NEWDECIMAL)
10056 282 (down_cast<Field_new_decimal *>(conv_field))->set_keep_precision(true);
10057 2589 conv_field->move_field(buf + 1, buf, 0);
10058 2589 conv_field->table = table;
10059 2589 conv_field->table_name = table_name;
10060
1/2
✓ Branch 0 taken 2589 times.
✗ Branch 1 not taken.
2589 conv_field->set_field_index(field_index());
10061
10062 // Swap arena so that the Item_field is allocated on TABLE::mem_root for
10063 // non-temp tables and so it does not end up in THD's item list which will
10064 // have a different lifetime than TABLE::mem_root
10065 5178 Query_arena tmp_arena(actual_mem_root, Query_arena::STMT_REGULAR_EXECUTION);
10066 5178 Query_arena backup_arena;
10067
2/4
✓ Branch 0 taken 2589 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2589 times.
✗ Branch 3 not taken.
2589 current_thd->swap_query_arena(tmp_arena, &backup_arena);
10068
2/4
✓ Branch 0 taken 2589 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2589 times.
✗ Branch 3 not taken.
2589 m_conv_item = new Item_field(conv_field);
10069
2/4
✓ Branch 0 taken 2589 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2589 times.
✗ Branch 3 not taken.
2589 current_thd->swap_query_arena(backup_arena, &tmp_arena);
10070 }
10071
10072 22 const char *Field_typed_array::get_index_name() const {
10073 22 uint key = part_of_key.get_first_set();
10074
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 assert(key != MY_BIT_NONE);
10075 22 return table->s->key_info[key].name;
10076 }
10077
10078 171 size_t Field_typed_array::make_sort_key(Json_wrapper *wr, uchar *to,
10079 size_t length) const {
10080 #ifndef NDEBUG
10081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 171 times.
171 switch (wr->type()) {
10082 case enum_json_type::J_ERROR:
10083 case enum_json_type::J_OBJECT:
10084 case enum_json_type::J_ARRAY:
10085 // Only scalars are supported
10086 assert(false);
10087 break;
10088 171 default:
10089 171 break;
10090 }
10091 #endif
10092 171 THD *thd = current_thd;
10093 // Force error on bad data
10094 #ifndef NDEBUG
10095 bool res =
10096 #endif
10097 171 save_json_to_field(thd, m_conv_item->field, wr, true);
10098 // Data should be already properly converted so no error is expected here
10099
2/4
✓ Branch 0 taken 171 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 171 times.
✗ Branch 3 not taken.
171 assert(!res && !thd->is_error());
10100
10101 171 return m_conv_item->field->make_sort_key(to, length);
10102 }
10103
10104 int Field_typed_array::do_save_field_metadata(uchar *metadata_ptr) const {
10105 *metadata_ptr = static_cast<uchar>(m_elt_type);
10106 switch (m_elt_type) {
10107 case MYSQL_TYPE_VARCHAR: {
10108 assert(field_length < 65536);
10109 char *param_ptr = (char *)(metadata_ptr + 1);
10110 int3store(param_ptr, field_length);
10111 return 4;
10112 }
10113 case MYSQL_TYPE_NEWDECIMAL: {
10114 assert(field_length < 128);
10115 uint8 precision = my_decimal_length_to_precision(field_length, decimals(),
10116 is_unsigned());
10117 *(metadata_ptr + 1) = precision;
10118 *(metadata_ptr + 2) = decimals();
10119 return 3;
10120 }
10121 case MYSQL_TYPE_LONGLONG:
10122 case MYSQL_TYPE_NEWDATE:
10123 return 1;
10124 case MYSQL_TYPE_TIME2:
10125 case MYSQL_TYPE_DATETIME2:
10126 *(metadata_ptr + 1) = decimals();
10127 return 2;
10128 case MYSQL_TYPE_YEAR:
10129 default:
10130 break;
10131 }
10132 assert(0); // Shouldn't happen
10133 return 0;
10134 }
10135
10136 425 void Field_typed_array::sql_type(String &str) const {
10137 425 const Field *const conv_field = m_conv_item->field;
10138 // There is no need to append the character set and collation to the type,
10139 // since utf8mb4_0900_bin is the only collation supported for arrays.
10140
3/4
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 339 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 86 times.
425 assert(!conv_field->has_charset() ||
10141 conv_field->charset() == &my_charset_utf8mb4_0900_bin);
10142 425 conv_field->sql_type(str);
10143 425 str.append(STRING_WITH_LEN(" array"));
10144 425 }
10145
10146 2 void Field_typed_array::make_send_field(Send_field *field) const {
10147 2 Field_json::make_send_field(field);
10148 // When sending the array to the client (only possible using the debug flag
10149 // show_hidden_columns), it should be sent as a JSON array. Set the type to
10150 // JSON instead of the array element type.
10151 2 field->type = MYSQL_TYPE_JSON;
10152 2 }
10153
10154 975 void Field_typed_array::set_field_index(uint16 field_index) {
10155 975 Field::set_field_index(field_index);
10156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 975 times.
975 if (m_conv_item) m_conv_item->field->set_field_index(field_index);
10157 975 }
10158
10159 388716 Key_map Field::get_covering_prefix_keys() const {
10160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 388716 times.
388716 if (table == nullptr) {
10161 // This function might be called when creating functional indexes. In those
10162 // cases, we do not have a table object available. Assert that the function
10163 // is indeed called in a functional index context, and then return an empty
10164 // key map.
10165 assert(down_cast<const Create_field_wrapper *>(this) != nullptr);
10166 return Key_map();
10167 }
10168 388716 Key_map covering_prefix_keys = part_of_prefixkey;
10169 388716 covering_prefix_keys.intersect(table->covering_keys);
10170 388716 return covering_prefix_keys;
10171 }
10172
10173 307679 void Field::set_default() {
10174
6/6
✓ Branch 0 taken 303604 times.
✓ Branch 1 taken 4075 times.
✓ Branch 2 taken 97 times.
✓ Branch 3 taken 303507 times.
✓ Branch 4 taken 4172 times.
✓ Branch 5 taken 303507 times.
611283 if (has_insert_default_datetime_value_expression() ||
10175 303604 has_insert_default_general_value_expression())
10176 4172 evaluate_insert_default_function();
10177 else
10178 303507 copy_data(table->default_values_offset());
10179 307679 }
10180
10181 1071360542 uint Field::null_offset() const { return null_offset(table->record[0]); }
10182
10183 75588923 void Field::init(TABLE *table_arg) {
10184 75588923 table = table_arg;
10185 75588923 table_name = &table_arg->alias;
10186 75588923 }
10187
10188 // Byteswaps and/or truncates int16 values; used for both pack() and unpack().
10189 134995 static inline void handle_int16(uchar *to, const uchar *from, size_t max_length,
10190 bool low_byte_first_from,
10191 bool low_byte_first_to) {
10192 int16 val;
10193 uchar buf[sizeof(val)];
10194
1/2
✓ Branch 0 taken 134995 times.
✗ Branch 1 not taken.
134995 if (low_byte_first_from)
10195 134995 val = sint2korr(from);
10196 else
10197 val = shortget(from);
10198
10199
1/2
✓ Branch 0 taken 134995 times.
✗ Branch 1 not taken.
134995 if (low_byte_first_to)
10200 134995 int2store(buf, val);
10201 else
10202 shortstore(buf, val);
10203
1/2
✓ Branch 0 taken 134995 times.
✗ Branch 1 not taken.
134995 if (max_length >= sizeof(buf)) {
10204 // Common case.
10205 134995 memcpy(to, buf, sizeof(buf));
10206 } else {
10207 memcpy(to, buf, max_length);
10208 }
10209 134995 }
10210
10211 // Byteswaps and/or truncates int24 values; used for both pack() and unpack().
10212 static inline void handle_int24(uchar *to, const uchar *from, size_t max_length,
10213 bool low_byte_first_from [[maybe_unused]],
10214 bool low_byte_first_to [[maybe_unused]]) {
10215 int32 val;
10216 uchar buf[3];
10217 #ifdef WORDS_BIGENDIAN
10218 if (low_byte_first_from)
10219 val = sint3korr(from);
10220 else
10221 #endif
10222 val = (from[0] << 16) + (from[1] << 8) + from[2];
10223
10224 #ifdef WORDS_BIGENDIAN
10225 if (low_byte_first_to)
10226 int3store(buf, val);
10227 else
10228 #endif
10229 {
10230 buf[0] = 0xFF & (val >> 16);
10231 buf[1] = 0xFF & (val >> 8);
10232 buf[2] = 0xFF & val;
10233 }
10234 if (max_length >= sizeof(buf)) {
10235 // Common case.
10236 memcpy(to, buf, sizeof(buf));
10237 } else {
10238 memcpy(to, buf, max_length);
10239 }
10240 }
10241
10242 // Byteswaps and/or truncates int32 values; used for both pack() and unpack().
10243 332610130 static inline void handle_int32(uchar *to, const uchar *from, size_t max_length,
10244 bool low_byte_first_from,
10245 bool low_byte_first_to) {
10246 int32 val;
10247 uchar buf[sizeof(val)];
10248
1/2
✓ Branch 0 taken 332610353 times.
✗ Branch 1 not taken.
332610130 if (low_byte_first_from)
10249 332610353 val = sint4korr(from);
10250 else
10251 val = longget(from);
10252
10253
1/2
✓ Branch 0 taken 332610779 times.
✗ Branch 1 not taken.
332610779 if (low_byte_first_to)
10254 332610779 int4store(buf, val);
10255 else
10256 longstore(buf, val);
10257
2/2
✓ Branch 0 taken 332610838 times.
✓ Branch 1 taken 334 times.
332611172 if (max_length >= sizeof(buf)) {
10258 // Common case.
10259 332610838 memcpy(to, buf, sizeof(buf));
10260 } else {
10261 334 memcpy(to, buf, max_length);
10262 }
10263 332611172 }
10264
10265 // Byteswaps and/or truncates int64 values; used for both pack() and unpack().
10266 167419516 static inline void handle_int64(uchar *to, const uchar *from, size_t max_length,
10267 bool low_byte_first_from [[maybe_unused]],
10268 bool low_byte_first_to [[maybe_unused]]) {
10269 int64 val;
10270 uchar buf[sizeof(val)];
10271 #ifdef WORDS_BIGENDIAN
10272 if (low_byte_first_from)
10273 val = sint8korr(from);
10274 else
10275 #endif
10276 167419516 memcpy(&val, from, sizeof(val));
10277
10278 #ifdef WORDS_BIGENDIAN
10279 if (low_byte_first_to)
10280 int8store(buf, val);
10281 else
10282 #endif
10283 167419516 longlongstore(buf, val);
10284
2/2
✓ Branch 0 taken 167419493 times.
✓ Branch 1 taken 23 times.
167419516 if (max_length >= sizeof(buf)) {
10285 // Common case.
10286 167419493 memcpy(to, buf, sizeof(buf));
10287 } else {
10288 23 memcpy(to, buf, max_length);
10289 }
10290 167419516 }
10291
10292 91395 uchar *Field::pack_int16(uchar *to, const uchar *from,
10293 size_t max_length) const {
10294 91395 handle_int16(to, from, max_length, table->s->db_low_byte_first, true);
10295 91395 return to + sizeof(int16);
10296 }
10297
10298 43600 const uchar *Field::unpack_int16(uchar *to, const uchar *from) const {
10299 43600 handle_int16(to, from, UINT_MAX, true, table->s->db_low_byte_first);
10300 43600 return from + sizeof(int16);
10301 }
10302
10303 uchar *Field::pack_int24(uchar *to, const uchar *from,
10304 size_t max_length) const {
10305 handle_int24(to, from, max_length, table->s->db_low_byte_first, true);
10306 return to + 3;
10307 }
10308
10309 const uchar *Field::unpack_int24(uchar *to, const uchar *from) const {
10310 handle_int24(to, from, UINT_MAX, true, table->s->db_low_byte_first);
10311 return from + 3;
10312 }
10313
10314 120393784 uchar *Field::pack_int32(uchar *to, const uchar *from,
10315 size_t max_length) const {
10316 120393784 handle_int32(to, from, max_length, table->s->db_low_byte_first, true);
10317 120394728 return to + sizeof(int32);
10318 }
10319
10320 212216351 const uchar *Field::unpack_int32(uchar *to, const uchar *from) const {
10321 212216351 handle_int32(to, from, UINT_MAX, true, table->s->db_low_byte_first);
10322 212216590 return from + sizeof(int32);
10323 }
10324
10325 45467767 uchar *Field::pack_int64(uchar *to, const uchar *from,
10326 size_t max_length) const {
10327 45467767 handle_int64(to, from, max_length, table->s->db_low_byte_first, true);
10328 45467767 return to + sizeof(int64);
10329 }
10330
10331 121951751 const uchar *Field::unpack_int64(uchar *to, const uchar *from) const {
10332 121951751 handle_int64(to, from, UINT_MAX, true, table->s->db_low_byte_first);
10333 121951751 return from + sizeof(int64);
10334 }
10335
10336 9057 bool Field_longstr::is_updatable() const {
10337
2/4
✓ Branch 0 taken 9057 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9057 times.
✗ Branch 3 not taken.
9057 assert(table && table->write_set);
10338 9057 return bitmap_is_set(table->write_set, field_index());
10339 }
10340
10341 8590614 Field_varstring::Field_varstring(uchar *ptr_arg, uint32 len_arg,
10342 uint length_bytes_arg, uchar *null_ptr_arg,
10343 uchar null_bit_arg, uchar auto_flags_arg,
10344 const char *field_name_arg, TABLE_SHARE *share,
10345 8590614 const CHARSET_INFO *cs)
10346 : Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
10347 auto_flags_arg, field_name_arg, cs),
10348 8590614 length_bytes(length_bytes_arg) {
10349
2/2
✓ Branch 0 taken 8589817 times.
✓ Branch 1 taken 802 times.
8590619 if (share != nullptr) {
10350 8589817 share->varchar_fields++;
10351 }
10352 8590619 }
10353
10354 2263691 Field_varstring::Field_varstring(uint32 len_arg, bool is_nullable_arg,
10355 const char *field_name_arg, TABLE_SHARE *share,
10356 2263691 const CHARSET_INFO *cs)
10357 : Field_longstr(nullptr, len_arg,
10358 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
10359 field_name_arg, cs),
10360
4/4
✓ Branch 0 taken 1370368 times.
✓ Branch 1 taken 893323 times.
✓ Branch 2 taken 1727836 times.
✓ Branch 3 taken 535854 times.
2263691 length_bytes(len_arg < 256 ? 1 : 2) {
10361
2/2
✓ Branch 0 taken 2263669 times.
✓ Branch 1 taken 21 times.
2263690 if (share != nullptr) {
10362 2263669 share->varchar_fields++;
10363 }
10364 2263690 }
10365
10366 76246084 void Field_blob::store_length(uchar *i_ptr, uint i_packlength,
10367 uint32 i_number) {
10368 76246084 store_blob_length(i_ptr, i_packlength, i_number);
10369 76246069 }
10370
10371 10890314 uint32 Field_blob::get_length(ptrdiff_t row_offset) const {
10372 10890314 return get_length(ptr + row_offset, this->packlength);
10373 }
10374
10375 248865083 uint32 Field_blob::get_length(const uchar *ptr_arg) const {
10376 248865083 return get_length(ptr_arg, this->packlength);
10377 }
10378
10379 25433 bool Field_blob::backup_blob_field() {
10380 25433 value.swap(m_blob_backup);
10381 #ifndef NDEBUG
10382 25433 m_uses_backup = true;
10383 #endif
10384 25433 return false;
10385 }
10386
10387 25433 void Field_blob::restore_blob_backup() {
10388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25433 times.
25433 assert(m_uses_backup);
10389 25433 value.swap(m_blob_backup);
10390 #ifndef NDEBUG
10391 25433 m_uses_backup = false;
10392 #endif
10393 25433 }
10394
10395 631 Create_field_wrapper::Create_field_wrapper(const Create_field *fld)
10396 1262 : Field(nullptr, fld->max_display_width_in_codepoints(), nullptr, 0,
10397 631 fld->auto_flags, fld->field_name),
10398 631 m_field(fld) {
10399
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 628 times.
631 if (fld->is_unsigned) {
10400 3 set_flag(UNSIGNED_FLAG);
10401 }
10402 631 }
10403
10404 1083 Item_result Create_field_wrapper::result_type() const {
10405 1083 return field_types_result_type[field_type2index(m_field->sql_type)];
10406 }
10407
10408 218 Item_result Create_field_wrapper::numeric_context_result_type() const {
10409 218 return ::numeric_context_result_type(type(), result_type(),
10410 436 m_field->decimals);
10411 }
10412
10413 219 enum_field_types Create_field_wrapper::type() const {
10414 219 return m_field->sql_type;
10415 }
10416
10417 const CHARSET_INFO *Create_field_wrapper::charset() const {
10418 return m_field->charset;
10419 }
10420
10421 uint32 Create_field_wrapper::pack_length() const {
10422 return m_field->pack_length();
10423 }
10424
10425 uint32 Create_field_wrapper::max_display_length() const {
10426 return m_field->max_display_width_in_codepoints();
10427 }
10428
10429 54247 Create_field *generate_create_field(THD *thd, Item *item, TABLE *tmp_table) {
10430 Field *tmp_table_field;
10431
2/2
✓ Branch 0 taken 5512 times.
✓ Branch 1 taken 48735 times.
54247 if (item->type() == Item::FUNC_ITEM) {
10432 /*
10433 If the function returns an array, use the method provided by the function
10434 to create the tmp table field, as the generic
10435 tmp_table_field_from_field_type() can't handle typed arrays.
10436 */
10437
6/6
✓ Branch 0 taken 2716 times.
✓ Branch 1 taken 2796 times.
✓ Branch 2 taken 132 times.
✓ Branch 3 taken 2584 times.
✓ Branch 4 taken 2928 times.
✓ Branch 5 taken 2584 times.
5512 if (item->result_type() != STRING_RESULT || item->returns_array())
10438 2928 tmp_table_field = item->tmp_table_field(tmp_table);
10439 else
10440 2584 tmp_table_field = item->tmp_table_field_from_field_type(tmp_table, false);
10441 } else {
10442 Field *from_field, *default_field;
10443
2/4
✓ Branch 0 taken 48735 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48735 times.
✗ Branch 3 not taken.
48735 tmp_table_field = create_tmp_field(thd, tmp_table, item, item->type(),
10444 nullptr, &from_field, &default_field,
10445 false, false, false, false);
10446 }
10447
10448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54247 times.
54247 if (!tmp_table_field) {
10449 return nullptr; /* purecov: inspected */
10450 }
10451
10452 Field *table_field;
10453
10454
2/2
✓ Branch 0 taken 44798 times.
✓ Branch 1 taken 9449 times.
54247 switch (item->type()) {
10455 44798 case Item::FIELD_ITEM:
10456 case Item::TRIGGER_FIELD_ITEM: {
10457 /*
10458 We have to take into account both the real table's fields
10459 and pseudo-fields used in trigger's body. These fields are used to copy
10460 defaults values later inside constructor of the class Create_field.
10461 */
10462 44798 table_field = ((Item_field *)item)->field;
10463 44798 break;
10464 }
10465 9449 default: {
10466 /*
10467 If the expression is of temporal type having date and non-nullable,
10468 a zero date is generated. If in strict mode, then zero date is
10469 invalid. For such cases no default is generated.
10470 */
10471 9449 table_field = nullptr;
10472
2/2
✓ Branch 0 taken 165 times.
✓ Branch 1 taken 269 times.
9883 if (is_temporal_type_with_date(tmp_table_field->type()) &&
10473
6/6
✓ Branch 0 taken 434 times.
✓ Branch 1 taken 9015 times.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 123 times.
✓ Branch 4 taken 42 times.
✓ Branch 5 taken 9407 times.
9883 thd->is_strict_mode() && !item->is_nullable())
10474 42 tmp_table_field->set_flag(NO_DEFAULT_VALUE_FLAG);
10475 }
10476 }
10477
10478
2/4
✓ Branch 0 taken 54247 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54247 times.
✗ Branch 3 not taken.
54247 assert(tmp_table_field->gcol_info == nullptr &&
10479 tmp_table_field->stored_in_db);
10480 Create_field *cr_field =
10481
2/4
✓ Branch 0 taken 54247 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54247 times.
✗ Branch 3 not taken.
54247 new (thd->mem_root) Create_field(tmp_table_field, table_field);
10482
10483
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54247 times.
54247 if (!cr_field) {
10484 return nullptr; /* purecov: inspected */
10485 }
10486
10487 // Mark if collation was specified explicitly by user for the column.
10488
2/2
✓ Branch 0 taken 44794 times.
✓ Branch 1 taken 9453 times.
54247 if (item->type() == Item::FIELD_ITEM) {
10489 44794 const TABLE *table = table_field->table;
10490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44794 times.
44794 assert(table);
10491 44794 const dd::Table *table_obj =
10492
2/2
✓ Branch 0 taken 27631 times.
✓ Branch 1 taken 17163 times.
44794 table->s->tmp_table ? table->s->tmp_table_def : nullptr;
10493
10494
3/4
✓ Branch 0 taken 44743 times.
✓ Branch 1 taken 51 times.
✓ Branch 2 taken 44743 times.
✗ Branch 3 not taken.
44794 if (!table_obj && table->s->table_category != TABLE_UNKNOWN_CATEGORY) {
10495
1/2
✓ Branch 0 taken 44743 times.
✗ Branch 1 not taken.
44743 dd::cache::Dictionary_client::Auto_releaser releaser(thd->dd_client());
10496
10497
4/8
✓ Branch 0 taken 44743 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44743 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 44743 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 44743 times.
44743 if (thd->dd_client()->acquire(table->s->db.str, table->s->table_name.str,
10498 &table_obj)) {
10499 return nullptr; /* purecov: inspected */
10500 }
10501
1/2
✓ Branch 0 taken 44743 times.
✗ Branch 1 not taken.
44743 }
10502
10503 44794 cr_field->is_explicit_collation = false;
10504
2/2
✓ Branch 0 taken 17214 times.
✓ Branch 1 taken 27580 times.
44794 if (table_obj) {
10505
2/4
✓ Branch 0 taken 17214 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17214 times.
✗ Branch 3 not taken.
17214 const dd::Column *c = table_obj->get_column(table_field->field_name);
10506
2/4
✓ Branch 0 taken 17214 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17214 times.
✗ Branch 3 not taken.
17214 if (c) cr_field->is_explicit_collation = c->is_explicit_collation();
10507 }
10508 }
10509
10510
2/2
✓ Branch 0 taken 22998 times.
✓ Branch 1 taken 31249 times.
54247 if (item->is_nullable()) cr_field->flags &= ~NOT_NULL_FLAG;
10511
10512 54247 return cr_field;
10513 }
10514
10515 12231424 const char *get_field_name_or_expression(THD *thd, const Field *field) {
10516
2/2
✓ Branch 0 taken 943 times.
✓ Branch 1 taken 12230491 times.
12231424 if (field->is_field_for_functional_index()) {
10517 943 String expression_buffer;
10518
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 field->gcol_info->print_expr(thd, &expression_buffer);
10519
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 return thd->strmake(expression_buffer.ptr(), expression_buffer.length());
10520 935 }
10521
10522 12230491 return field->field_name;
10523 }
10524